Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ Questions: need response urgently

Name: Anonymous 2010-04-27 23:23

I'm working on my final project for my Object-Oriented programming class. The language I'm using (and that the course was taught based around) is C++. We have relatively simple projects that we designed in a previous class and now we're implementing them.

 I'm in a situation where I need to have an STL vector that includes items from two different child classes derived from the same parent class. The parent class never exists on its own, and the only difference between the child classes is the value of a boolean return function that returns "true" for one child class and "false" for the other. I realize it's stupid, but we were required to shoehorn class inheritance into our projects somewhere.

What I did was create a vector of the parent class and then push_down() items of the child classes into it. I try to compile after every significant bit of coding to make sure I havent broken anything, and the compiler (Microsoft VS 2008) had no issue with doing that. But when I try to write a for loop to access items of every item of the vector in sequence, it tells me that the function added in the child class doesn't exist.

I know I'm doing this wrong somehow, but I don't know what I should do about it. I'm due to give a presentation tomorrow, and I'm pretty sure my professor's asleep by now, so I can't ask him.

Help me, /prog/! Please!

Name: Anonymous 2010-04-28 0:00

Watch me troll classical Pragusticians by HELPING HIM

>>1
If the function wasn't originally defined in the parent class and overridden in the child classes, then the compiler won't know it exists. Learn to use virtual.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List