Original Post
Hello all, I have a question in regards to initializing a struct through the constructor. My situation was something like this:
struct A
{
int m_baseInt;
};
struct B : public A
{
B( int baseInt, int subInt ) : m_baseInt( baseInt ), m_subInt( subInt ){}
int m_subInt;
};
The compiler throws an error here. It tells me that "m_baseInt is not a member of B". This seems odd to me, aren't all member variables in structs public by default? So shouldn't I have access to a public member of my base class? After poking around the net for initialization examples, I replaced it with the following code that I found:
struct A
{
A( int baseInt ) : m_baseInt( baseInt ){}
m_baseInt;
};
struct B
{
B( int baseInt, int subInt ) : A( baseInt ), m_subInt( subInt ){}
m_subInt;
};
So, is this the way I should initialize the members of my base class? And if so, why don't I have access to those member variables when the constructor is executing? I'd appreciate any insight. Thanks much, jujumbura