如何在类定义之外的模板类中定义模板函数?

Bry*_*man 34 c++ templates

鉴于:

template <class T>
class Foo
{
public:
    template <class U>
    void bar();
};
Run Code Online (Sandbox Code Playgroud)

如何在仍然可以访问模板参数T和U的同时在类定义之外实现bar?

Any*_*orn 42

IIRC:

template<class T> template <class U>
void Foo<T>::bar() { ...
Run Code Online (Sandbox Code Playgroud)

  • @Xeo它有两个独立的模板,类和功能.(我想那就是为什么) (4认同)
  • @Xeo因为它是`Foo <T> :: bar <U>`,而不是`Foo <T,U> :: bar` (3认同)