Accessing member variables post template inheritance

J

Joseph Paterson

Hi all,

I'm writing a simple Stack class, that inherits from a Stack Interface,
IStack.
IStack has a protected member variable, m_root

I have:
--snip--
template <class T>
class IStack
{
//...
protected:
struct entry * m_root;
};

template <class T>
class Stack : public IStack<T>
{
public:
Stack()
{
m_root = 0;
}
};
--snip--

This does not compile, the compiler can't see m_root inside Stack.
However, if I call it with this->m_root, it compiles.

Any clues?

Thanks,

Joseph.
 
M

mlimber

Joseph said:
I'm writing a simple Stack class, that inherits from a Stack Interface,
IStack.
IStack has a protected member variable, m_root

I have:
--snip--
template <class T>
class IStack
{
//...
protected:
struct entry * m_root;
};

template <class T>
class Stack : public IStack<T>
{
public:
Stack()
{
m_root = 0;
}
};
--snip--

This does not compile, the compiler can't see m_root inside Stack.
However, if I call it with this->m_root, it compiles.

Any clues?

See this FAQ:

http://www.parashift.com/c++-faq-lite/templates.html#faq-35.19

Cheers! --M
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top