M
Mark A. Gibbs
Good day,
i'm having a bit of trouble with a base class i'm working on. this is
what it boils down to:
template <typename T>
class foo
{
protected:
foo() { T* p = static_cast<T*>(this); }
};
class bar : foo<bar>
{
public:
bar() {}
};
as is bar inherits privately from foo, and i get a compile error on the
assignment saying "Illegal access from bar to private/protected member
foo::" (that's exactly what it says, just "foo::").
when i use public inheritance, there's no problem. however, i get the
same problem for protected inheritance, or when i make foo::foo() a
public constructor.
is there a reason for this? i mean, when foo::foo() is instantiated, the
relationship between foo and T is known and clear. i don't see what
private member of foo bar is trying to access. i tried making a
workaround by doing this:
int distance = static_cast<foo<T>*>((T*)0);
T* p = reinterpret_cast<T*>(this - distance);
but it still failed on the first line.
i'm using codewarrior 8. what i want to do is get a pointer to the
derived class from the base class.
--
Mark A. Gibbs (aka. Indi)
Administrator
#c++ on irc.Rizon.net
http://ca.geocities.com/[email protected]/
(temporary website)
i'm having a bit of trouble with a base class i'm working on. this is
what it boils down to:
template <typename T>
class foo
{
protected:
foo() { T* p = static_cast<T*>(this); }
};
class bar : foo<bar>
{
public:
bar() {}
};
as is bar inherits privately from foo, and i get a compile error on the
assignment saying "Illegal access from bar to private/protected member
foo::" (that's exactly what it says, just "foo::").
when i use public inheritance, there's no problem. however, i get the
same problem for protected inheritance, or when i make foo::foo() a
public constructor.
is there a reason for this? i mean, when foo::foo() is instantiated, the
relationship between foo and T is known and clear. i don't see what
private member of foo bar is trying to access. i tried making a
workaround by doing this:
int distance = static_cast<foo<T>*>((T*)0);
T* p = reinterpret_cast<T*>(this - distance);
but it still failed on the first line.
i'm using codewarrior 8. what i want to do is get a pointer to the
derived class from the base class.
--
Mark A. Gibbs (aka. Indi)
Administrator
#c++ on irc.Rizon.net
http://ca.geocities.com/[email protected]/
(temporary website)