Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/143.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在函数头中使用remove_引用_C++_C++11 - Fatal编程技术网

C++ 在函数头中使用remove_引用

C++ 在函数头中使用remove_引用,c++,c++11,C++,C++11,假设我有以下几点: template <typename... A> class MyClass { public: void func(A... args) { // do stuff } }; 模板 类MyClass { 公众: 无效函数(A…args) { //做事 } }; 我真正想要的是func()接受l值引用,所以类似这样: template <typename... A> class MyClass { publ

假设我有以下几点:

template <typename... A>
class MyClass
{
public:

    void func(A... args)
    {
        // do stuff
    }
};
模板
类MyClass
{
公众:
无效函数(A…args)
{
//做事
}
};
我真正想要的是func()接受l值引用,所以类似这样:

template <typename... A>
class MyClass
{
public:

    void func(std::remove_reference<A>::type&... args)
    {
        // do stuff
    }
};
模板
类MyClass
{
公众:
void func(std::remove_reference::type&…args)
{
//做事
}
};
这不是编译;这可能吗?谢谢。

代码应为

template <typename... A>
class MyClass
{
public:

    void func(typename std::remove_reference<A>::type&... args)
    {
        // do stuff
    }
};
模板
类MyClass
{
公众:
void func(typename std::remove_reference::type&…args)
{
//做事
}
};

clangerror:“错误:在依赖类型名称'std::remove_reference::type'之前缺少'typename'”注意,在C++14中,您只需使用:
void func(std::remove_reference_t&…args){…}