Problem accessing base member in derived constructor
Posted
by LeopardSkinPillBoxHat
on Stack Overflow
See other posts from Stack Overflow
or by LeopardSkinPillBoxHat
Published on 2010-06-01T06:08:17Z
Indexed on
2010/06/01
6:13 UTC
Read the original article
Hit count: 219
Given the following classes:
class Foo
{
struct BarBC
{
protected:
BarBC(uint32_t aKey)
: mKey(aKey)
mOtherKey(0)
public:
const uint32_t mKey;
const uint32_t mOtherKey;
};
struct Bar : public BarBC
{
Bar(uint32_t aKey, uint32_t aOtherKey)
: BarBC(aKey),
mOtherKey(aOtherKey) // Compile error here
};
};
I am getting a compilation error at the point indicated:
error: class `Foo::Bar' does not have any field named `mOtherKey'.
Can anyone explain this? I suspect it's a syntactical problem due to my Bar
class being defined within the Foo
class, but can't seem to find a way around it.
This is simple public inheritance, so mOtherKey
should be accessible from the Bar
constructor. Right?
Or is it something to do with the fact that mOtherKey
is const and I have already initialised it to 0
in the BarBC
constructor?
© Stack Overflow or respective owner