This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Template class heritance strange behaviour
- From: "rodrigo benenson" <rodrigo dot benenson at inria dot fr>
- To: gcc-help at gcc dot gnu dot org
- Cc: "SÃverin Lemaignan" <severin dot lemaignan at inria dot fr>
- Date: Wed, 14 Mar 2007 13:57:18 +0100
- Subject: Template class heritance strange behaviour
I have a question about the namespace management when heriting a
templated class.
Given the following code, why the member variable 'c' is managed
differently than the member method 'set_c' ?
Thanks for you explanations.
rodrigob.
http://www-rocq.inria.fr/~benenson/
The following code compiles.
//////////////////////////////////////////
template<typename T1>
class Parent
{
public:
T1 c;
void set_c(T1 &val)
{
c = val;
}
};
template<typename T2>
class Child : Parent<T2>
{
T2 d;
public:
void set_d(T2 _d)
{
d = _d;
//c = _d; // <<< this line generates error : 'c' was not declared
in this scope
this->c = _d; // this access work fine
Parent<T2>::c = _d; // this access work fine too
set_c(_d); // there is no problem in finding 'set_c' in the scope
}
};
int main(void)
{
Child<int> the_child;
the_child.set_d(5);
return 0;
}
//////////////////////////////////////////
Command:
g++ test.cpp -o test && ./test
g++ --version
g++ (GCC) 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)