Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > scope of template-inherited members

Reply
Thread Tools

scope of template-inherited members

 
 
filip.konvicka@gmail.com
Guest
Posts: n/a
 
      12-19-2007
Hi, I'm having problems with the following code:

template<typename T> struct A {
T i;
};

template<typename T> struct B : public A<T> {
void access_i() { i; }
};

g++ 4.2.2 complains that

'i' was not declared in this scope

in B<T>::access_i() definition. Of course, when I use

void access_i() { A<T>::i; }

everything's OK, but I don't see why I need to use this. Can anyone
please explain why this is?

The code compiles fine with MSVC, and I'd like to keep the code
readable...

Thanks,
Corn
 
Reply With Quote
 
 
 
 
filip.konvicka@gmail.com
Guest
Posts: n/a
 
      12-19-2007
To answer myself... this is because of C++ standard's [temp.dep]/3,
and the following suffices:

void access_i() { this->i; }

Sorry for the noise.

Corn

(E-Mail Removed) napsal:
> Hi, I'm having problems with the following code:
>
> template<typename T> struct A {
> T i;
> };
>
> template<typename T> struct B : public A<T> {
> void access_i() { i; }
> };
>
> g++ 4.2.2 complains that
>
> 'i' was not declared in this scope
>
> in B<T>::access_i() definition. Of course, when I use
>
> void access_i() { A<T>::i; }
>
> everything's OK, but I don't see why I need to use this. Can anyone
> please explain why this is?
>
> The code compiles fine with MSVC, and I'd like to keep the code
> readable...
>
> Thanks,
> Corn

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
class members vs instance members hdixon Python 3 07-09-2006 06:56 PM
Difference between static final members and final static members(if any)? JFCM Java 4 02-07-2006 11:32 AM
Which members are created automatically, which members are not inherited? lovecreatesbeauty C Programming 43 02-06-2006 11:36 PM
Templates: Members Vs. non-members Dave C++ 3 08-10-2004 11:23 AM
Can nested class members access private members of nesting class? CoolPint C++ 8 12-14-2003 02:30 PM



Advertisments