Is there a way to call a member function of a parent class in a child class?
How can I implement call_print_in_Base
below?
class Base{
public:
void print() { cout << "i'm base!" << endl; }
};
class Derived : public Base{
public:
void print() {
call_print_in_Base() ///<-here
cout << "i'm Derived!" << endl;
}
};
C++ supports multiple inheritance, so to eliminate ambiguity
There are no base class keywords such as super
in java
or base
in C#
.
Instead, add ::
(two colons) after the name of the base class.
class Base{
public:
void print() { cout << "i'm base!" << endl; }
};
class Derived : public Base{
public:
void print() {
Base::print();
cout << "i'm Derived!" << endl;
}
};
© 2024 OneMinuteCode. All rights reserved.