Original Post
In the following code I'd like the "omg[0].x();" thing to print 2 as well. Is there a way to do that? (without pointers). Thanks
class Test1
{
public:
virtual void x()
{
std::cout << "1";
}
};
class Test2 : public Test1
{
public:
void x()
{
std::cout << "2";
}
};
int main(int argc, char *argv[])
{
Test2 test;
std::vector<Test1> omg;
std::vector<Test1*> omgp;
omg.push_back(test);
omgp.push_back(&test);
test.x(); //this prints 2
omg[0].x(); //this prints 1 while I'd like to to print 2
omgp[0]->x(); //this prints 2
}