call a childs version of a function instead of a parents?

Okay, so I got two classes.

class a{
public:
a(){};
void print(){cout << "hello"};
}

class b : public a{
public:
void print(){cout << "hello world";}
}

And a array of parents with a child

a blah[10];
blah[5] = b();

Than I call print, and want it to say hello world.

blah[5].print();

But it calls the parent. How do I fix this?

8
задан cHao 26 December 2011 в 04:53
поделиться