I like to have well defined interface in a few classes, for this I created pure virtual functions in an abstract class that each class needs to implement.
But I'm facing the problem that I can instantiate the classes so I have to create another class that inherit the interface class, and all the other classes needs to inherit from this base class. Here is the code for example:
The interface
class Interface
{
virtual std::string getName() = 0;
}
class Base : public Interface
{
virtual std::string getName(return std::string("Base") ;)
}
class A : public Base
{
std::string getName(return std::string("A") ;)
}
class B : public Base
{
std::string getName(return std::string("B") ;)
}
All this so i could in code to have the same type for A & B.
Can I just use the Interface
class without the Base
class?
Something like this:
class A : public Interface
{
std::string getName(return std::string("A") ;)
}