0

I am declaring a template class and defining the methods on an inline file

(foo.hpp)

template<typename T>
class Foo {
public:
  using Result = T::Result;

  Foo();
  ~Foo();

  Result Bar();
};

(foo-inl.hpp)

template<typename T>
Result Foo<T>::Bar() {
  ...
}

But I get an error

error: 'Result' does not name a type;

I thought, since i declare Bar as part of Foo<T> the method definition should know about Result

Any suggestons on how to fix it?

Symlink
  • 383
  • 2
  • 12
  • TL;DR of the dupe: `using Result = T::Result;` needs to be `using Result = typename T::Result;` to tell the compiler the dependent name is a type. Otherwise it assumes it is an object. – NathanOliver Feb 01 '21 at 13:24
  • Also, `Result Foo::Bar()` needs to be `Foo::Result Foo::Bar() ` as `Result` is scoped to `Foo`. – NathanOliver Feb 01 '21 at 13:25
  • You would need `Foo::Result` or simply `T::Result` since at the point of mentioning `Result` you are not inside `Foo` scope. – stiar Feb 01 '21 at 13:25

0 Answers0