scope of template-inherited members

F

filip.konvicka

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
 
F

filip.konvicka

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 address removed) napsal:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top