S
softwaredoug
Here is some test code I've been attempting to compile (Visual Studio
2003)
test.h:
class Base
{
protected:
Base() {}
public:
template <class T>
static T* GetInstance() {return new T;} /*ERROR HERE */
};
class Derived
{
protected:
Derived() {}
};
class SomeCode
{
static void SomeCodeForYa();
};
test.cpp:
#include "test.h"
void SomeCode::SomeCodeForYa()
{
Derived* T = Base::GetInstance<Derived>();
}
I consistently get a compiler error: "error C2248:
'Derived:erived' : cannot access protected member declared in class
'Derived'"
This *seems* like it should be allowed so long as the template
parameter is a derived from base. Am I missing something here? Is this
legal C++?
2003)
test.h:
class Base
{
protected:
Base() {}
public:
template <class T>
static T* GetInstance() {return new T;} /*ERROR HERE */
};
class Derived
{
protected:
Derived() {}
};
class SomeCode
{
static void SomeCodeForYa();
};
test.cpp:
#include "test.h"
void SomeCode::SomeCodeForYa()
{
Derived* T = Base::GetInstance<Derived>();
}
I consistently get a compiler error: "error C2248:
'Derived:erived' : cannot access protected member declared in class
'Derived'"
This *seems* like it should be allowed so long as the template
parameter is a derived from base. Am I missing something here? Is this
legal C++?