Hello,
Okay, here's the problem. I'm trying to create a linked list of abstract Object types, so I can use more complex (and extending) derivations of this Object class in the linked list. Follow so far?
The code in the game is more complex, but this code below gives the right idea (I've used an array instead of a linked list for simplicity)
Output only gives:Code:class Base{ public: virtual void doSomething(){ std::cout << " - - - - " << std::endl; } }; // - - - - - - - - - - - - - - - - - - - - - - - - class Extended : public Base{ public: void doSomething(){ std::cout << "Doing something..." << std::endl; } }; // - - - - - - - - - - - - - - - - - - - - - - - - int main(int argc, char* argv[]){ Base baseObj; Extended extensionObj; Base objs[2]; objs[0] = baseObj; objs[1] = extensionObj; objs[0].doSomething(); objs[1].doSomething(); return 0; }
- - - -
- - - -
Rather than:
- - - -
Doing something...
Could someone please point me in the right direction? I don't understand why the overriding method in objs[1] is not called, like it should be..Thanks!