This works for me:
Code:
#include <iostream>
#include <string>
using namespace std;
class Base
{
public:
virtual string getName() const = 0;
//I want this to call the implemented getName
string getSomething()
{ return ( "Base." + getName() ); }
};
class Derived : public Base
{
public:
virtual string getName() const
{ return "Derived"; }
};
int main()
{
Derived x;
std::cout << x.getSomething() << std::endl;
}
Note that since Base is a polymorphic abstract base class, it should have a virtual destructor.
Also,
declare a function named d that has no parameters and returns a Derived object.
The function getSomething() (which is defined as a base function) is called from the Base constructor.
That is problematic. Virtual functions should never be called (directly or indirectly) from the constructor.