Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/127.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.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++ 将代码移出类定义时,参数包未展开_C++_Variadic Templates_C++17_Fold - Fatal编程技术网

C++ 将代码移出类定义时,参数包未展开

C++ 将代码移出类定义时,参数包未展开,c++,variadic-templates,c++17,fold,C++,Variadic Templates,C++17,Fold,我的模板类如下所示: template<typename... Args> class Foo { public: void Bar() { (std::get<Args>(m_args).Bar(), ...); } private: std::tuple<Args...> m_args; }; 模板 福班 { 公众: 空条(){ (std::get这东西看起来像MSVC bug,在使用折叠表达式时会复制。 因此,

我的模板类如下所示:

template<typename... Args>
class Foo
{
public:
    void Bar() {
        (std::get<Args>(m_args).Bar(), ...);
    }

private:
    std::tuple<Args...> m_args;
};
模板
福班
{
公众:
空条(){

(std::get

这东西看起来像MSVC bug,在使用折叠表达式时会复制。 因此,解决方案是从C++ 17到C++ 14的代码,使用“经典”代码>初始化列表列表> /COD> HACK:< /P>
template<typename... Args>
void Foo<Args...>::Bar() {
    (void)std::initializer_list<int>{
        (std::get<Args>(m_args).Bar(), 0)...
    };
}
模板
void Foo::Bar(){
(无效)标准::初始值设定项列表{
(std::get(m_args).Bar(),0)。。。
};
}

看起来像是MSVC的错误。请向Microsoft提交错误报告,并从这里链接到该报告,以便其他人知道何时修复该错误。
template<typename... Args>
void Foo<Args...>::Bar() {
    (std::get<Args>(m_args).Bar(), ...);
}
error C3520: 'Args': parameter pack must be expanded in this context
note: while compiling class template member function 'void Foo<Test<0>,Test<1>>::Bar(void)'
note: see reference to function template instantiation 'void Foo<Test<0>,Test<1>>::Bar(void)' being compiled
note: see reference to class template instantiation 'Foo<Test<0>,Test<1>>' being compiled
error C2228: left of '.Bar' must have class/struct/union
error C2059: syntax error: '...'
template<typename... Args>
void Foo<Args...>::Bar() {
    (void)std::initializer_list<int>{
        (std::get<Args>(m_args).Bar(), 0)...
    };
}