【发布时间】:2026-01-13 22:10:01
【问题描述】:
在下面的代码中,如何使用列表b来创建object_b,就像使用列表a手动创建object_a一样?
#include <list>
template <int...Args>
class Object {};
int main() {
std::list<int> a = {1,2,3,4,5};
Object<1,2,3,4,5> object_a;
std::list<int> b;
// do whatever with b
// Object< ? > object_b; // how to use b to create object_b?
}
【问题讨论】:
-
这在 C++ 中是不可能的。您不能将运行时对象转换为编译时模板。
-
list a未用于创建object_a(手动或其他方式)。 -
这是不可能的。也许您想改用
std::tuple<...>?