ezod
ezod

Reputation: 7421

Public inheritance of a class template fails unexpectedly

Why does the following fail with error: 'a_' was not declared in this scope in the context of Bar::get()?

template <typename N>
class Foo
{
public:
  Foo() { }

protected:
  N a_;
};

template <typename N>
class Bar : public Foo<N>
{
public:
  Bar() : Foo<N>() { }

  N get() { return a_; }
};

Upvotes: 0

Views: 38

Answers (1)

Saher Ahwal
Saher Ahwal

Reputation: 9237

You need to use the reference this->_a

N get() { return this->a_; }

Upvotes: 1

Related Questions