I have an exercise dealing with classes in c++, in which I create a file system like so (File.h
)
class File {
public:
virtual string getName();
virtual void print() const=0;
virtual bool operator==(const File& file) const=0;
}
Then, I implement getName
in File.cpp
and create TextFile.h
class TextFile : public File {
public:
void print() const;
void operator==(const TextFile& textFile) const;
private:
string text_;
Implement in TextFile.cpp
void TextFile :: print() const {
cout << text_ << endl;
}
bool TextFile :: operator==(const TextFile& textFile) const {
return true; //just for compiling
}
when compiling we get:
$ g++ -Wall -g File.cpp TextFile.cpp -o RunMe
TextFile.cpp: In function ‘int main()’:
TextFile.cpp:8:11: error: cannot declare variable ‘Ilan’ to be of abstract type ‘TextFile’
TextFile Ilan("Ilan", NULL, "Blah \n NewLine");
^
In file included from TextFile.cpp:1:0:
TextFile.h:8:7: note: because the following virtual functions are pure within ‘TextFile’:
class TextFile: public File
^
In file included from TextFile.h:4:0,
from TextFile.cpp:1:
File.h:57:18: note: virtual bool File::operator==(const File&) const
virtual bool operator==(const File& file) const = 0;
I probably don't know how to work well with inheritance and operator functions (seeing the print
function works well), but I can't find the problem when looking through my course material.