从此可变参数模板启用共享

Gam*_*per -1 c++ variadic-templates c++11

基本上我有一个可变参数类,除了“启用从此共享”部分之外,它工作得很好。

template <typename S>
class Test;

template <typename... Args>
class Test < void( Args...)>: 

        public std::enable_shared_from_this
        < Test< void(Args...)> >
{

    public:
        std::shared_ptr< Test< void( Args...)>> getptr();

};

template <typename... Args>
std::shared_ptr< Test< void( Args...)>>  Test < void( Args...)>::getptr(){
    return shared_from_this(); // error here!
}
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

there are no arguments to 'shared_from_this' that depend on a template parameter, 
so a declaration of 'shared_from_this' must be available [-fpermissive]
Run Code Online (Sandbox Code Playgroud)

Dan*_*rey 5

你需要

return this->shared_from_this();
Run Code Online (Sandbox Code Playgroud)

(假设其余的只是拼写错误,这可能是因为您收到的错误消息。您显然需要从 派生std::enable_shared_from_this< Test< void(Args...)> >