-
March 29th, 2025, 04:21 AM
#1
abstract class and derived class
Given this example, because I need to confirms my ideas:
Code:
class Father {
public:
virtual void pureF() = 0;
virtual void simpleF() {}
};
class Child : Father {
public:
virtual void pureF();
};
1st question:
If I understood correctly, in this example if I was not interesting to define SimpleF in the derived class, It's mandatory to define It in the base class.
If I had this instruction in Father class:
Code:
virtual void simpleF();
I will get error because derived class inherits simpleF but this function would not be defined in any class. Right ?
2nd question:
Father class is abstract so it's not possible to create any instance of base Class.
Derived class inherits both pureF and simpleF function.
If I didn't redefine pureF function in the derived class, Child class would inherit this virtual function which would turn derived class to abstract class and I should have to add new derived class where to define function, right ?
This example is only for education purpose.
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|