access to members of template base class

J

John Femiani

Hi all,

I have come across a problem using g++. The example below illustrates
the issue:

--------------------------------------------------------
#include <iostream>

template<class T>
struct A {
int member;
};;

template<class T>
struct B: A<T> {
void somefunc() {
std::cout << member << std::endl;
}
};

------------------------------------------


The code above compiles with vc8 but not g++ 3.4.2.
g++ complains that there is no symbol named 'member'..
If A and B are not a template classes then there is no problem.


Is there a bug in g++? or vc8? What is the proper behavior here?

Note that if I use this->member it compiles with g++ for some reason.

Thanx,
-- John
 
V

Victor Bazarov

John said:
I have come across a problem using g++. The example below illustrates
the issue:

--------------------------------------------------------
#include <iostream>

template<class T>
struct A {
int member;
};;

template<class T>
struct B: A<T> {
void somefunc() {
std::cout << member << std::endl;
}
};

------------------------------------------


The code above compiles with vc8 but not g++ 3.4.2.
g++ complains that there is no symbol named 'member'..
If A and B are not a template classes then there is no problem.


Is there a bug in g++? or vc8? What is the proper behavior here?

Note that if I use this->member it compiles with g++ for some reason.

Search the FAQ (and the archives) for "dependent name". You can
answer your own question if you do some reading first.

V
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top