Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/124.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++;由模板指定的类成员_C++ - Fatal编程技术网

C++ C++;由模板指定的类成员

C++ C++;由模板指定的类成员,c++,C++,是否可以使用可变模板来指定类的成员?一个可接受的解决方案是将数据存储在元组内部 template <typename ... Args> struct FromPP { // TODO: Get the tuple type from parameter pack std::tuple<> data; // TODO: write the constructors // Other code... E.g. A prin

是否可以使用可变模板来指定类的成员?一个可接受的解决方案是将数据存储在元组内部

template <typename ... Args> 
struct FromPP {
     // TODO: Get the tuple type from parameter pack
     std::tuple<> data;    
     // TODO: write the constructors

     // Other code... E.g. A print method, and manipulations with 
     // other points of the same type... 
}
模板
struct FromPP{
//TODO:从参数包获取元组类型
std::元组数据;
//TODO:编写构造函数
//其他代码…例如打印方法和使用
//相同类型的其他点。。。
}
理想情况下,我想要一些同时具有默认构造函数和复制构造函数的实现:

FromPP<float>();    // decltype(data) == std::tuple<float>
FromPP<float>(1.1); // decltype(data) == std::tuple<float>

FromPP<float,int>();       // decltype(data) == std::tuple<float,int>
FromPP<float,int>(1.1, 5); // decltype(data) == std::tuple<float,int>
FromPP();//decltype(数据)==std::tuple
FromPP(1.1);//decltype(数据)==std::tuple
FromPP();//decltype(数据)==std::tuple
FromPP(1.1,5);//decltype(数据)==std::tuple
等等


如果可能的话,我想要一个C++11解决方案。我们使用的一些硬件支持spotty C++14。

如果您对元组没有意见,可以按如下方式定义结构:

template <typename... Args> 
struct FromPP {
   std::tuple<Args...> data;    

   FromPP() = default;
   FromPP(Args&&... args) : data(std::forward<Args>(args)...) { }
};
模板
struct FromPP{
std::tuple


这是你想要的吗?

std::tuple data;
只是想知道:它有什么用处?你打算做什么?tuple
做不到的是什么?你可以用这个类做很多事情,还有一些其他方法…一个打印方法,以及对相同类型的其他点的一些操作。但是你不能在这些方法中使用这些数据,不是吗?为什么它是类的一部分,不只是一个单独的元组?