Bloomberg LP Interview Question
Software Engineer / DevelopersDerived object contains Base part and possibly additional things. When you write
Base *b = new Derived();
a Derived object is created and pointer b points to start of Base part. However when you write
Derived *d = new Base();
a Base object is created which has no knowledge about Derived part and don't know where d should point to. So this is invalid.
1. It's not allowed.
2. The problem: 'this' is implicitly passed to every non-static member function of the class. When Derived's member function tries to access Derived's data member through a pointer to a Base object something bad will happen. Derived's part just doesn't exist.
3. Another question is "what about virtual functions?"
1) user can call some function which is not defined in the base class
- Anonymous March 23, 20102) by the help of casting it is allowed
What else???????