1234567891011121314151617181920212223242526272829303132333435363738394041 |
- #include <iostream>
- using namespace std;
- class BaseClass {
- public:
- void fn1() {
- cout << "the fn1 founction of the baseclass" << endl;
- }
- void fn2() {
- cout << "the fn2 founction of the baseclass" << endl;
- }
- };
- class DerivedClass : public BaseClass {
- public:
- void fn1() {
- cout << "the fn1 founction of the DerivedClass" << endl;
- }
-
- void fn2() {
- cout << "the fn2 founction of the DerivedClass" << endl;
- }
- };
- int main() {
- DerivedClass derivedObj;
- derivedObj.fn1();
- derivedObj.fn2();
- BaseClass* basePtr = &derivedObj;
- basePtr->fn1();
- basePtr->fn2();
- DerivedClass* derivedPtr = &derivedObj;
- derivedPtr->fn1();
- derivedPtr->fn2();
- return 0;
- }
|