Quick question: I thought that member initializing lists acted the same as normal initialization using '=' (except for const members which can only be defined using initializing lists), calling the constructors of the to-be-initialized objects with specific arguments that I'm passing, as in my below example (where I'm calling x's constructor with a value of 1). But to my surprize, in the case of a simple inheritance, the compiler complains for not seeing the member I'm trying to initialize with my constructor, although seeing the other one that gets initialized with usual '=' syntax:
#include <iostream>
using namespace std;
class A
{
public:
int x;
int y;
};
class B : public A
{
public:
B() : x(1)
{
y = 2;
}
};
int main()
{
return 0;
}
If you run the above code, you'll see that while y gets detected with no problems, your compiler will say there is no such member named 'x' at the 'B() : x(1)' line. Why is that? The inheritance is public, y gets seen, no problems there, why not x as well?