Template class heritance strange behaviour

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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)

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux