0

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_; }
};
ezod
  • 7,261
  • 2
  • 24
  • 34

1 Answers1

1

You need to use the reference this->_a

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

Saher Ahwal
  • 9,015
  • 32
  • 84
  • 152