So I have a base class Base and a few child classes. What I want to do is have a base class constructor that creates a child class based on a string argument, like:
Base:Base(string class_name) {
switch(class_name) {
case "something":
*this = SomeChildClass(...);
...
}
}
This compiles and runs but the object doesn't have the characteristics of the child class and I don't understand why. Shouldn't this work?
Basein your code?*this = new SomeChildClass(...);should not compile, since the left hand side is a reference and the right hand side is a pointer.:,switchon string, etc.