#include <iostream>
usingnamespace std;
class Base
{
public:
Base() {cout<<"Base::Base()" <<endl;}
Base(int v) {cout<<"Base::Base(int v)" <<endl;}
void foo() {cout<<"Base::foo()" <<endl;}
};
class Derived: public Base
{
public:
Derived() {cout<<"Derived::Derived()" <<endl;}
Derived(int v) :Base(v) {cout<<"Derived::Derived(int v)" <<endl;}
void foo() {cout<<"Derived::foo()" <<endl;}
};
int main()
{
Base* pThing = new Derived();
pThing->foo();
return 0;
}
which outputs:
Base::Base()
Derived::Derived()
Base::foo()
What I really want to happen is that the Derived::foo() is invoked in place of the Base::foo()
The only thing I have the liberty of changing is my Derived class. This is an issue I am having with a project in a class of mine and the instructor created the main function and the Base class. My job was to develop the Derived class. I would like to state again, I can not change the Base class or the Main function.
Another thing I would like to state is that I believe my teacher to be an idiot, and as such, it is very possible that what I am trying to do here is impossible. If it is just let me know and I will go talk to him.