[ create a new paste ] login | about

Link: http://codepad.org/aB6zAyq5    [ raw code | output | fork ]

C++, pasted on Jan 11:
class Parent {
int parentX;
public:
     Parent(){;}
     virtual ~Parent(){;}

     virtual int getId(){return 1;}
};

class Child : public Parent
{
int childX;
public:
     Child(){;}
     virtual int getId(){return 2;}
};

void doStuff(Parent* p)
{
printf("%d", p->getId());
}


int main(void)
{
// Assume we have a instance of Director, and call the doStuff function here:
doStuff(new Child()); // Gives error

return 0;
}


Output:
1
2


Create a new paste based on this one


Comments: