What does the error message mean ?
Your MSVC error message corresponds to the precise case where you derive a class Directory
from an abstract class File
:
1>c:\users\talw\desktop\hw5\hw5\project1\main.cpp(76): error C2259:
'Directory' : cannot instantiate abstract class
1> due to following members:
The compiler explains you that you've inherited from an abstract member function that is not overriden in your new class:
1> 'bool File::operator ==(const File &) const' : is abstract
1> c:\users\talw\desktop\hw5\hw5\project1\file.h(57) : see
declaration of 'File::operator =='
How to fix it ?
To make your Directory class a concrete class, you must first declare operator==
in the class to override it (note that the keyword override
is optional):
class Directory : public File {
//...
public:
bool operator==(const File& file) const override ;
};
And then you shall provide the definition for the DERIVED class:
bool Directory::operator==(const File& file) const {
return true;
}
Is this the only solution ?
If your intent was however to really define the virtual function for the class File
, then you simply have to remove the =0
for operator==
in your class definition. File::operator==
will then be the default implementation of the virtual function for all the derived classes, unless they override it with a more specific one.