L
laniik
Hi. I have a simple question, but I couldnt find the answer in any
literature online.
i have a base class A, that has some functions. now, my understanding
of virtual functions means that in:
class A {
virtual void foo() = 0;
void bar() {cout<<"bar"<<endl;}
};
class B : public A {
void foo() {cout<<"foo"<<endl;}
void bar() {cout<<"bar2"<<endl;}
};
every class B that derives class A *must* define foo or I get a linker
error.
also, if class B defines bar, it will call the bar from class A rather
than B. i.e. print out bar rather than bar2
What i want is to have a function defined in A that if it isnt defined
in B, then it uses the one in A
if it is defined in B, then it uses the one in B. (but it doesnt
*have* to be defined) how do i do this? thanks!
oliver
literature online.
i have a base class A, that has some functions. now, my understanding
of virtual functions means that in:
class A {
virtual void foo() = 0;
void bar() {cout<<"bar"<<endl;}
};
class B : public A {
void foo() {cout<<"foo"<<endl;}
void bar() {cout<<"bar2"<<endl;}
};
every class B that derives class A *must* define foo or I get a linker
error.
also, if class B defines bar, it will call the bar from class A rather
than B. i.e. print out bar rather than bar2
What i want is to have a function defined in A that if it isnt defined
in B, then it uses the one in A
if it is defined in B, then it uses the one in B. (but it doesnt
*have* to be defined) how do i do this? thanks!
oliver