How to have multiple virtual functions along inheritance chain? Why does the call to this->Init() in 'MoreSpecific' class cause unresolved external symbol error?
When this code is encountered it will always be dealing with an instance of MostSpecificA or MostSpecificB which should then be able to access the child class implementations.
class GenericInterface
{
public:
virtual void Init() = 0; //virtual function
virtual void Startup() = 0;
};
class MoreSpecific : public GenericInterface
{
virtual void Init() = 0; //we cannot yet define Init implementation here, not enough information
void Startup() {
this->Init(); //this throws unresolved external symbol error
}
//other shared functionality
};
class MostSpecificA : public MoreSpecific
{
void Init() {
//the implemention for MostSpecificA
}
};
class MostSpecificB : public MoreSpecific
{
void Init() {
//the implemention for MostSpecificB
}
};
Edit, actually the above code does work. The error occurs when calling Init() from the constructor. Following code produces unresolved external symbol error, which matches what is occurring in my code.
class GenericInterface
{
public:
virtual void Init() = 0; //virtual function
};
class MoreSpecific : public GenericInterface
{
public:
virtual void Init() = 0; //we cannot yet define Init implementation here, not enough information
MoreSpecific() {
this->Init();
}
//other shared functionality
};
class MostSpecificA : public MoreSpecific
{
public:
MostSpecificA()
: MoreSpecific()
{
}
void Init() {
//the implemention for MostSpecificA
}
};
class MostSpecificB : public MoreSpecific
{
void Init() {
//the implemention for MostSpecificB
}
};