Write a c++ class to implement hierarchy two class are inheriting a single class for example a and b are inheriting class c | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Write a c++ class to implement hierarchy two class are inheriting a single class for example a and b are inheriting class c

c++ hierarchy code please give me the code of inheritance

27th Mar 2018, 6:50 PM
Manisha R Gupta
Manisha R Gupta - avatar
1 Answer
0
Like you wanted Classes A and B inherit from C and when you run it, objects objA and objB will use the printC() function/method which they inherited from class C. If you have any further questions about this code be sure to ask! #include <iostream> using namespace std; class C { public: void printC() { cout << "Class C print func" << endl; } }; class A: public C { public: void printA() { cout << "Class A print func" << endl; } }; class B: public C { public: void printB() { cout << "Class B print func" << endl; } }; int main() { A objA; B objB; objA.printC(); objA.printA(); objB.printC(); objB.printB(); return 0; }
27th Mar 2018, 9:40 PM
TurtleShell
TurtleShell - avatar