Protected member inheritence in templated classes

R

ramunasg

Hello,

g++ refuses to compile the following code, by saying that "pt" is not
in the scope of "Second" class (when I add scope by changing "pt = 0"
to "First<T>::pt = 0" g++ comples clenely), but VC++ 8 compiles without
problems. So my questions is what is the syntax (and semantics) for
accessing protected members in templeted classes?

template <class T>
class First {
protected:
T *pt;
};

template <class T>
class Second public First<T> {
public:
Antras() { pt = 0; }
};


Thanks in advance :)
 
M

Markus Moll

Hi

g++ refuses to compile the following code, by saying that "pt" is not
in the scope of "Second" class (when I add scope by changing "pt = 0"
to "First<T>::pt = 0" g++ comples clenely), but VC++ 8 compiles without
problems. So my questions is what is the syntax (and semantics) for
accessing protected members in templeted classes?

It has nothing to do with protected members, but with dependent names, and
template <class T>
class First {
protected:
T *pt;
};

template <class T>
class Second public First<T> {
^
This produces another error here. :)
public:
Antras() { pt = 0; }
};

Google for "two-phase name lookup"

Markus
 

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
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top