Macro_FTW
2009-08-14 19:11:48
[[[EDIT]]] I have my answer (B.) Thanks. :) [[[/EDIT]]]
Hello all.
Just a quick question on how virtual works in C++.
Say I had code like this:
Will that print out 'a', or 'b'?
In other terms, I'm asking if a virtual method is declared and used in a superclass, but the same method is overwritten in the subclass, will the subclass' method be used in any superclass-only method calls for it?
Thanks!
~Macro_FTW
Hello all.
Just a quick question on how virtual works in C++.
Say I had code like this:
//Includes are assumed
class Base {
public:
virtual char getChar() { return 'a'; }
char sayChar() { cout << getChar(); }
};
class Adv: public Base {
public:
char getChar() { return 'b'; }
};
void main() {
Adv a;
cout << a.sayChar();
}Will that print out 'a', or 'b'?
In other terms, I'm asking if a virtual method is declared and used in a superclass, but the same method is overwritten in the subclass, will the subclass' method be used in any superclass-only method calls for it?
Thanks!
~Macro_FTW