C
Christopher
If I have an generic interface, but _also_ have the implementation for
it and want to use that common implementation in my derived classes,
what method does that leave me to make pure virtual such that my
generic interface class cannot be instantiated?
Do you make the destructor virtual?
Do you move constructors to private?
// What do I make pure virtual??
AbstractClass
{
public:
AbstractClass() {}
virtual AbstractClass() {}
virtual void Foo()
{
std::cout << "Foo!" << std::endl;
}
};
DerivedClass : public AbstractClass
{
public:
DerivedClass() {}
~DerivedClass() {}
void Bar()
{
std::cout << "Bar!" <<std::endl;
}
};
I don't want anyone to be able to:
AbstractClass * abstract = new AbstractClass();
I do want people to be able to:
AbstractClass * abstract = new DerivedClass();
abstract->Foo();
and expect:
"Foo!"
it and want to use that common implementation in my derived classes,
what method does that leave me to make pure virtual such that my
generic interface class cannot be instantiated?
Do you make the destructor virtual?
Do you move constructors to private?
// What do I make pure virtual??
AbstractClass
{
public:
AbstractClass() {}
virtual AbstractClass() {}
virtual void Foo()
{
std::cout << "Foo!" << std::endl;
}
};
DerivedClass : public AbstractClass
{
public:
DerivedClass() {}
~DerivedClass() {}
void Bar()
{
std::cout << "Bar!" <<std::endl;
}
};
I don't want anyone to be able to:
AbstractClass * abstract = new AbstractClass();
I do want people to be able to:
AbstractClass * abstract = new DerivedClass();
abstract->Foo();
and expect:
"Foo!"