   (C++) Inherited variable in template class can't be found. - SOLVED
  I'm trying to access a publicly defined member of a template base class from within a template inherited class. Unfortunately, somehow the name cannot be resolved.template <typename T>class A {  public:    T m_x;};template <typename T>class B : public A<T> {  public:    void foo() { m_x = 1; } <--- This SHOULD work, right?    // void foo() { A<T>::m_x = 1; } <--- This fixes the problem, but I shouldn't have to do this, right?};int main() {    B<int> b;    b.foo();    return 1;}Compilation Error:error: 'm_x' was not defined in this scopeIf I remove the templates and declare m_x as int, the program compiles OK.Looking at the C++ standard:http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1905.pdfit seems that this should compile.(P34, 3.3.6.2)Am I reading that right?EDIT: Compiled using code::blocks under linux using it's default compiler, GNU GCC Compiler.Thanks for all assistance.[Edited by - Skarsha on June 5, 2006 3:34:30 AM]
  lol, I asked the same question ealier today. Check it out:  my thread;  This has nothing to do with scope.  The problem is that the compiler has no guarenttee that you don't have this somewhere:int m_x;template<>class A<int> {  public:    int m_y;};B<int> b;Which means that instances of B<int> won't have a member called m_x.  Why does this generate an error though, surely the compiler will see that when it instantiates B<int>?  Well, what if you happen to have a global that's also called m_x?  If you didn't need to explicitly say you're expecting A<T> to contain a member called m_x the compiler would happily modify the global, which obviously isn't what you want.   ;  Ah, good explanation joanus.That thread seems to answer it also.Pity you can't explicitly prevent template overloading.   