I am trying to learn about C++ inheritance, but one thing doesn't make any sense to me. Everything a googled about what is not inherited by a derived class said that the constructors, friends, and operator= are not inherited. However, this information doesn't fit with the results of my program.
I did an example of inheritance and the result is what follows:
#include <iostream>
using namespace std;
class Base
{
public:
Base()
{
cout << "constructor base class without parameters" << endl;
}
Base(int a)
{
cout << "constructor base class with int parameter" << endl;
}
Base(const Base& b)
{
cout << "copy constructor base class" << endl;
}
Base& operator= (const Base& base)
{
cout << "operator= base class" << endl;
}
};
class Derived: public Base
{
};
int main()
{
Derived d;
cout << endl << "here 1" << endl << endl;
Derived d2 = d;
cout << endl << "here 2" << endl << endl;
d = d2;
//Derived d3 (3); // ERROR!!
}
The output was:
constructor base class without parameters
here 1
copy constructor base class
here 2
operator= base class
If all the constructors and operator= are not inherited, why were operator=, default constructor and copy constructor of the base class called?