I am currently programming a program which searches song according to diffrent parameters. In my system there are 2 types of songs: lyric and instrumetal. Since i need to put both of them in 1 vector, I have a song class and a LyricsSong & InstrumentalSong subclasses.
So I there is a Song.h file:
#include <stdio.h>
#include <iostream>
#include <string>
class Song
{
public:
std::string title;
virtual void print();
virtual void printSong(std::string query);
};
and there are the instrumental and lyrics subclasses, which are defined this way:
class LyricsSong : public Song
class InstrumentalSong : public Song
both of the include Song.h, and in both of them the class is defines only in the header file.
when I try to run another file which use the both subclasses, and includes:
#include "LyricsSong.h"
#include "InstrumentalSong.h"
(and obviously more cpp libraries), i get the following compilation error:
In file included from /cygdrive/c/Users/Username/Documents/C++ Workshop/ex2/ex2_code/InstrumentalSong.h:16:0,
from /cygdrive/c/Users/Username/Documents/C++ Workshop/ex2/ex2_code/songsParser.cpp:26:
/cygdrive/c/Users/Username/Documents/C++ Workshop/ex2/ex2_code/Song.h:6:7: error: redefinition of 'class Song'
class Song
^
In file included from /cygdrive/c/Users/Username/Documents/C++ Workshop/ex2/ex2_code/LyricsSong.h:15:0,
from /cygdrive/c/Users/Username/Documents/C++ Workshop/ex2/ex2_code/songsParser.cpp:25:
/cygdrive/c/Users/Username/Documents/C++ Workshop/ex2/ex2_code/Song.h:6:7: error: previous definition of 'class Song'
class Song
^
when:
- lines InstrumentalSong.h:16:0 and LyricsSong.h:15:0 are where i include "Song.h"
- lines songsParser.cpp:25 and songsParser.cpp:26 are where i include InstrumentalSong.h and LyricsSong.h
- line Song.h:6:7: is the defination of Song.h (where it's say's class Song, as showed above).
What should I do? P.S. I do not import any cpp file ever, only header files.