class A {
public:
virtual void f() {}
virtual void g() {}
};
class B: public A {
public:
void f () {} //overriding A::f()
B() { f(); //calls B::f()
g(); //g() not overriden in B, therefore calling A::g() }
};
Mind that if the object's member functions use object data members, it is the implementor's responsibility to initialize them first, preferably by a mem-initializer list:
class C {
int n;
int getn() const { cout<
C(int j) : n(j) { getn(); } //Fine: n initialized before getn()
//is called; otherwise - n would
//have an undefined value
};
No comments:
Post a Comment