Last active
November 17, 2015 23:23
-
-
Save saifthe1/467275dfb65de0a7ef2b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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