相关疑难解决方法(0)

表达式包含未展开的参数包

不知怎的,我不知道如何扩展可变参数模板参数包.以下代码有什么问题?

#include <iostream>

template <typename T>
struct print_one
{
    static void run(const T& t)
    {
        std::cout << t << ' ';
    }
};

template<typename... Args>
void print_all(Args&&... args)
{
    // the next line doesn't compile:
    print_one<Args>::run(std::forward<Args>(args))...;
}

int main()
{
    print_all(1.23, "foo");
}
Run Code Online (Sandbox Code Playgroud)

Clang说,Expression contains unexpanded parameter packs 'Args' and 'args'.为什么?

c++ templates variadic-templates c++11

14
推荐指数
2
解决办法
1万
查看次数

标签 统计

c++ ×1

c++11 ×1

templates ×1

variadic-templates ×1