I've just been trying to port something on windows to linux. The following example compiles just fine in VS2010 and fails in g++ with main.cpp:17:31: error: ‘data’ was not declared in this scope
(g++ (GCC) 4.7.2 20121109 (Red Hat 4.7.2-8)
). Is there some workaround for accessing the base class without a tonne of casting? Is this even supported by the standard?
#include <stdio.h>
class A {
public:
int data;
A() {data = 42;}
};
template<typename T>
class B : public A {
};
template<typename T>
class C : public B<T> {
public:
void print() {printf("%i\n", data);}
};
int main()
{
C<char> c;
c.print();
return 0;
}
[EDIT] The following change compiles fine in gcc.
void print() {printf("%i\n", this->data);}