Create object of unknown class (two inherited classes)
- by Paul
I've got the following classes:
class A {
void commonFunction() = 0;
}
class Aa: public A {
//Some stuff...
}
class Ab: public A {
//Some stuff...
}
Depending on user input I want to create an object of either Aa or Ab. My imidiate thought was this:
A object;
if (/*Test*/) {
Aa object;
} else {
Ab object;
}
But the compiler gives me:
error: cannot declare variable ‘object’ to be of abstract type ‘A’
because the following virtual functions are pure within ‘A’:
//The functions...
Is there a good way to solve this?