-
Inheritance Fun
Say I have class A and class B as follows:
Code:
class A {
public:
void dostuff(void) { cout<<"A is doing stuff"<<endl; }
};
class B : public A{
public:
void dostuff(void) { cout<<"B is doing stuff"<<endl; }
};
Then if I execute the following code:
Code:
vector<A*> alist;
alist.push_back(new A());
alist.push_back(new B());
for(int i=0;i<2;++i) {
(alist.at(i))->dostuff();
}
The output will be:
Code:
A is doing stuff
A is doing stuff
My problem is that I want B's dostuff() function to get called the second time instead of A's... any way to do that?
Edit: On an unrelated note, how do some of you manage to get the syntax highlighting in your code tags?
-
-
Crap, wrong forum. Any mods mind moving this to the C++ board?
-
As for the syntax highlighter I know most just use a program to do it for you. I used this http://www.codeguru.com/Cpp/misc/sam...icle.php/c4693 (Its for windows).
-
Too much Java? You forgot to declare the function virtual.
-
-
I use a syntax highliter like prog-bman said. I coded mine in Java, so if you need something multi-platform, I'll send it along to you... I'll warn you ahead of time that it's somewhat buggy though.
the most common problems: too much highlighting (ifstream)
escape characters in strings:
Code:
int main()
{
std::cout<<"qoth the raven, \"nevermore\"";
return 0;
}
-
ah major looks like its time for you to rewrite it in c++ and
compete in the new contest :)
-
I thought about it... ATM I'm too busy, and if I had the time, I'd work on fixing that version up... and when I'm done with that, I have other plans for it...