L
Lionel B
Greetings,
The following code:
<code>
template<typename T>
class A
{
protected:
T n;
};
template<typename T>
class B : public A<T>
{
public:
void foo()
{
n = 1; // <--------- error
}
};
int main()
{
B<int> b;
b.foo();
return 0;
}
</code>
generates the error:
test.cpp: In member function `void B<T>::foo()':
test.cpp:15: error: `n' undeclared (first use this function)
If the base class member n is qualified with the full templated base
class name, as in:
A<T>::n = 1; // <--------- ok
it compiles fine. Also, for /non/ templated classes it is not necessary
to qualify the base class member name.
Could the compiler not infer from the templated class declarations that
the n in foo() refers to A<T>::n ?
Problem is, that in my real-world code there are (at least) four
template parameters and *many* inherited base class members; having to
quote the full templated base class name for every reference to an
inherited base class member would make my code incredibly clunky and
utterly unreadable. Is there a workaround for this?
Regards,
The following code:
<code>
template<typename T>
class A
{
protected:
T n;
};
template<typename T>
class B : public A<T>
{
public:
void foo()
{
n = 1; // <--------- error
}
};
int main()
{
B<int> b;
b.foo();
return 0;
}
</code>
generates the error:
test.cpp: In member function `void B<T>::foo()':
test.cpp:15: error: `n' undeclared (first use this function)
If the base class member n is qualified with the full templated base
class name, as in:
A<T>::n = 1; // <--------- ok
it compiles fine. Also, for /non/ templated classes it is not necessary
to qualify the base class member name.
Could the compiler not infer from the templated class declarations that
the n in foo() refers to A<T>::n ?
Problem is, that in my real-world code there are (at least) four
template parameters and *many* inherited base class members; having to
quote the full templated base class name for every reference to an
inherited base class member would make my code incredibly clunky and
utterly unreadable. Is there a workaround for this?
Regards,