Skip to content

Instantly share code, notes, and snippets.

@saifthe1
Last active November 17, 2015 23:23
Show Gist options
  • Save saifthe1/467275dfb65de0a7ef2b to your computer and use it in GitHub Desktop.
Save saifthe1/467275dfb65de0a7ef2b to your computer and use it in GitHub Desktop.
// The base class
class Base {
private:
int someNumber_;
public:
void printNumber(){
cout << "Printing number from base " << someNumber_ << endl;
}
virtual void func1(){
cout << "printing from base::func1" << endl;
}
virtual void func2(){
cout << "Printing from base::func2" << endl;
}
virtual void func3(){
cout << "Printing from base::func3" << endl;
}
};
// class devived1
class Derived1 : public Base {
public:
void func1(){
cout << "printing from Derived::func1" << endl;
}
virtual void func3(){
cout << "Printing from base::func3" << endl;
}
};
//class derived2
class Derived2 : public Base {
public:
void func2(){
cout << "printing from Derived::func2" << endl;
}
};
int main(){
Derived1 d1;
Base &b = d1;
b.printNumber();
b.func1();
b.func3();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment