Well your code doesn't work like I think you intended. The overloaded Derived* ctors are never called.
You're jumping through hoops to do quesitonable things, anyway.
The whole idea of deriving classes and polymorphism is that you don't need to know whether or not an object is of a derived type. The "is a" relationship is what you're going for.
For example, let's illustrate this with the below:
1 2 3 4 5 6 7 8 9 10 11
|
class Dog
{};
class Poodle : public Dog // A Poodle "is a" Dog
{};
class DogWalker
{
public:
DogWalker(Dog* dogtowalk); // a DogWalker walks dogs
};
|
The idea here is that you can write code for 'DogWalker' so that he can walk
ANY Dog, not just Poodles. DogWalker doesn't even need to know the different kinds of dogs (and it shouldn't -- because that would make maintanance more difficult). The whole point is that you write the code once, and it will work for any and all Dogs that may be created in the future.
In your example you're trying to have your Something class figure out what derived type it's working with. While this is
sometimes necessary, it's actually quite rare to have to do this. And it sets off red flags in my brain like you're doing something you shouldn't.
What exactly are you trying to accomplish? Forget about the Base/Derived/Something classes and tell me the
actual classes you're working with and what they represent (and why you feel you need to know whether or not you have a derived instance). There must be a way to design this better.