Hi,
I have a doubt regarding inheritance of base class constructor by inherited class.
I was recently going through some C++ online tutorial when I came across this piece of code:
#include <iostream>
class Foo
{
public:
Foo() { std::cout << "Foo's constructor" << std::endl; }
};
class Bar : public Foo
{
public:
Bar() { std::cout << "Bar's constructor" << std::endl; }
};
int main()
{
// a lovely elephant ;)
Bar bar;
}
I will quote the exact text present in the site from where I took the above code :
The object bar is constructed in two stages: first, the Foo constructor is invoked and then the Bar constructor is invoked. The output of the above program will be to indicate that Foo's constructor is called first, followed by Bar's constructor.
Now, my question is:
Will the constructor Foo() be called when an object of class Bar is declared?
This is the site from where I got the above code:
Initialization Lists in C++
Now according to the site, the constructor Foo() will be called. But as per my knowledge, this is not true since base class constructors are not inherited. But I want to confirm this.
Regards,