No subject


Tue Apr 3 04:57:33 UTC 2007


names even before the template is used (expanded in
some other part of the code).

And because while parsing the template the compiler
doesnt know "T", it also cant expand the base class
(SixStore) and therefore wouldnt know about the
"store" member variable.

Explicitly saying that it is a member variable
(this->store, or SixStore<T>::store) must turn off the
checking -- I´m betting that if you use something like
"this->xxx" it will only yield an error during the
first template instantiation.

But I dont have a C++ compiler (g++) here to check for
that :(, so I´m just guessing.

If you find out, pls let us know :)

good luck,

jan





 --- Dr Mark H Phillips <mark at austrics.com.au>
escreveu: 
> Hi,
> 
> The recent versions of g++ (in contrast to 3.3.*
> versions) will no
> longer compile:
> 
>   #include <iostream>
>   
>   template<typename T> struct SixStore {
>     int store; SixStore(): store(6) {}
>   };
>   
>   template<typename T> struct Six: public
> SixStore<T> {
>     int six() {return store;}
>   };
>   
>   int main() {
>     Six<char> s;
>     std::cout<<"six = "<<s.six()<<std::endl;
>   }
> 
> It complains with:
> 
>   tst3.cc: In member function `int Six<T>::six()':
>   tst3.cc:8: error: `store' undeclared (first use
> this function)
> 
> If I remove the template stuff however, it compiles
> fine.  I had
> a look on the GCC website and on the page
> 
>   http://gcc.gnu.org/bugs.html#known
> 
> I found the following information:
> 
>   This also affects members of base classes, see
> [14.6.2]: 
>                 template <typename> struct A
>                 {
>                     int i, j;
>                 };
>                 
>                 template <typename T> struct B :
> A<T>
>                 {
>                     int foo1() { return i; }      
> // error
>                     int foo2() { return this->i; }
> // OK
>                     int foo3() { return B<T>::i; }
> // OK
>                     int foo4() { return A<T>::i; }
> // OK
>                 
>                     using A<T>::j;
>                     int foo5() { return j; }      
> // OK
>                 };
> 
> and foo1() seems to be pretty much what I was
> unsuccessfully trying to 
> do!  But why does g++ now outlaw this?  Presumably
> the answer lies in
> 14.6.2 of the standard, but I do not have a copy of
> this and I can't
> find it anywhere on the web.  Can anyone enlighten
> me on what is happening
> here and why this kind of access to base-class
> members has been outlawed??
> 
> Thanks,
> 
> Mark.
> 
> 
> 
> _______________________________________________
> This is the Linux C++ Programming List
> :
> http://lists.linux.org.au/listinfo/tuxcpprogramming
> List
>  


	
	
		
_______________________________________________________ 
Yahoo! Acesso Grátis - Instale o discador do Yahoo! agora. http://br.acesso.yahoo.com/ - Internet rápida e grátis




More information about the tuxCPProgramming mailing list