Answer the question
In order to leave comments, you need to log in
Order of calling constructors when inheriting?
Hello.
I'm not entirely clear in what ORDER the constructors are called when inheriting?
Example:
#include <iostream>
using namespace std;
class Parent
{
public:
int m_Id;
Parent(int Id = 0)
: m_Id(Id)
{
cout << "Parent\n";
}
int GetId() const { return m_Id; }
};
class Child : public Parent
{
public:
double m_Value;
Child(double Value = 0.0)
: m_Value(Value)
{
cout << "Child\n";
}
double GetValue() const { return m_Value; }
};
int main()
{
Parent p;
Child c;
return 0;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question