To begin with, what I know about the C ++ standard (ISO / IEC 14882: 2003): section 11.5, paragraph 1, and this is not the case (but it seems that the compiler does not think so).
I try to call the protected base class method in the derived class method using this pointer, statically-casted to the base class pointer and in MSVC2008 error C2248: "A :: f": cannot access the protected member declared in class "A" .
I need to do this in the context of a “curiously repeating template pattern”, but I can reproduce this error in simpler code, as shown below:
class B
{
protected:
void f(){}
};
class D : public B
{
public:
void g()
{
f();
this->f();
static_cast<B*>(this)->f();
dynamic_cast<B*>(this)->f();
((B*)this)->f();
}
};
D d; d.g();
, , ?
, ?
, :
template<class T>
class B
{
public:
void g()
{
f();
this->f();
static_cast<T*>(this)->f();
}
};
class D : public B<D>
{
protected:
void f(){}
};
, this- > f();
, , , class E : public B<D> {...};: , static_cast .