How to reference a data field of a parent template class

X

Xin Wang

In ansi c++, you can do something like
template <class T>
class vector<T>
{
protected:
int a;
int b;
}

class boundedVector<T> : public vector<T>
{
protected:
int c;
}

And you can use the fields of vector as if they are defined for
boundedVector, but these are no longer allowed by ansi, right?

Xin Wang
 
D

David White

Xin Wang said:
In ansi c++, you can do something like
template <class T>
class vector<T>
{
protected:
int a;
int b;
}

Missing semi-colon.
class boundedVector<T> : public vector<T>
{
protected:
int c;
}

Missing semi-colon.
And you can use the fields of vector as if they are defined for
boundedVector, but these are no longer allowed by ansi, right?

I don't understand your question. Under what circumstances do you mean "use
the fields of vector as if they are defined for boundedVector"? A
boundedVector<T> inherits the members of vector<T>. It has always been the
case, and remains so, that a class inherits the members of its base
class(es), if any. Is that what you are asking about?

DW
 

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,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top