I am trying to create a base and a derived class with a const member that has to be initialized:
class baseClan
{
public:
baseClan(const string firstName)
:
fullName(createFullName(firstName))
{}
private:
const string lastName = "Smith";
const string fullName;
virtual const string createFullName(string firstName) { return firstName + " " + lastName ; }
}
How do I implement the derived class so that it can use a differently implemented createFullName? I am looking at this link https://isocpp.org/wiki/faq/strange-inheritance#calling-virtuals-from-ctor-idiom but it seems like I'm stuck between a rock and a hard place: the first approach it proposes (using init) is not applicable to initialization list; while in the second approach it is explicitly stated that it cannot handle the case where we need to access the instance data declared in Derived.