How to initialize object dynamically in the program without inheritance in c++? For example i Have class A and class B. And depend on condition i need to create instance of object but i don't know exactly what object i need to create, it depends on information that user input;
Example code:
int i;
cin>>i>>endl;
void *obj;
if(i)
obj = new A();
else
obj = new B();
do_something_with_either_matrix_or_vector(obj);function call. That means both Vector and Matrix share some properties, which in turn means that yes, abstract class (think interface in java/c#) would be good fit.