Android ndk gcc problem with inherited attribute
Hi,
I've got another problem (as in "Inheritance and friendship" post) and
I don't know if it comes from a C++ misuse or from a compiler error.
Visual Studio 2010 builds correctly but android ndk r9 gcc returns an
error.
The error refers to the line
mInt += 1 ;
and is:
error: 'mInt' was not declared in this scope
I think I can solve changing the line in
Base<T>::mInt += 1 ;
.... but why? My original code was wrong? Are there anydownsides with the
change I've applied? Or is it a good thing to do everytime?
The code is very similar to the previuous I posted:
---- MaGoTest.hpp BEGIN ----
template <class T>
class Base
{
public:
static void Build()
{
new T() ;
}
protected:
static int mInt ;
} ;
template<class T>
int Base<T>::mInt ;
template <class T>
class Der : public Base< T >
{
public:
static void Build()
{
mInt += 1 ;
Base<T>::Build() ;
}
} ;
class A : public Der< A >
{
template <class T> friend class ::Base ;
template <class T> friend class ::Der ;
private:
A() ;
} ;
---- MaGoTest.hpp END ----
---- MaGoTest.cpp BEGIN ----
#include "MaGoTest.hpp"
#include <iostream>
A::A()
{
std::cout << "A constructor" << std::endl ;
}
---- MaGoTest.cpp END ----
---- main.cpp BEGIN ----
#include "MaGoTest.hpp"
int main( void )
{
A::Build() ;
return 0 ;
}
---- main.cpp END ----