如何在<double>矢量中创建复杂类型的模板<T>?
How can I create template of complex<double> type in vector<T>?
我正在尝试使用如下所示的类创建数据结构,但是我在模板实现方面遇到了问题,因为该类型实际上很复杂。Sry 我没有使用正确的术语,而是使用如下所示的类代码:
template<class T>
class tableType
{
public:
string key;
vector<T> setValue;
~tableType();
tableType operator = (const tableType& obj) {
this->key = obj.key;
this->setValue = obj.setValue;
}
};
template<class typechosen>
class dataContainer :public tableType {
public:
vector<tableType<double>> ordNts;
vector<tableType<typechosen>> fields;
string type;
~dataContainer();
dataContainer operator = (const dataContainer& obj) {
this->ordNts = obj.ordNts;
}
};
例如,当我创建一个类变量时的示例数据类型,它应该是格式
dataContainer<complex<double>> dataStore;
dataStore.ordNts; //will be of type vector<tableType<double>>
dataStore.fields; //will be of type vector<tableType<complex<double>>>
如何实现这种类型的模板?
下面是一些工作代码:
#include <string>
#include <vector>
#include <complex>
template<class T>
class tableType
{
public:
std::string key;
std::vector<T> setValue;
};
template<class T>
class dataContainer
{
public:
std::vector<tableType<double>> ordNts;
std::vector<tableType<T>> fields;
std::string type;
};
int main()
{
dataContainer<std::complex<double>> dataStore;
auto j = dataStore.fields;
}
dataContainer
不应该有基类(好吧,无论如何,不是基于您到目前为止发布的要求(。
还要检查您是否在 C++11 或更高版本模式下进行编译(C++>>
11 中添加了使用令牌终止两个模板(。
如果您仍然遇到问题,请编辑问题以包含最小可重现示例。正如评论中所推测的那样,也许您错过了实际代码中的一些包含或std::
,或者其他内容。
铌。类有一个隐式生成的operator=
所以除非你需要不同的行为,否则你不应该编写自己的,这个类不应该,参见三/五/零规则。 同样,您可能不应该定义自己的析构函数。保持代码尽可能简单可以减少出错的机会,并更容易检查代码的正确性。
相关文章:
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 呼叫运营商<<临时
- 如何防止clang格式在流运算符调用之间添加换行符<<
- <<操作员在下面的行中工作
- EASTL矢量<向量<int>>连续的
- C - 创建矢量&lt; vector&lt; double&gt;&gt;矩阵具有分配而不是inizializ
- 为什么将此对向量&lt; map&lt; int,int&gt;&gt;中的地图进行更新.失败
- C :对矢量进行排序&lt; struct&gt;(结构有2个整数)基于结构的整数之一
- 明确的专业化“ CheckIntmap&lt;&gt;”实例化
- 什么是模板&lt;&gt;inline bla bla
- 编辑C Qlist&lt; object*&gt; gt;QML代码和一些QML警告中的模型
- eigen :: llt&lt;eigen :: matrixxd&gt;具有不完整的类型
- 错误,包括&lt; ctype&gt;在原子上使用C 11
- std::vector<;uint8_t>;当C++11/14启用时,手动复制而不是调用memcpy
- 如何加入向量&lt; int&gt;到C 中的单个INT
- 是std :: set&lt; std :: future&gt;不可能存在
- 是numeric_limits&lt; int&gt; :: is_modulo从逻辑上矛盾
- opencv 2.4.7在iOS错误背景_segm.hpp #include&lt; list&gt;未找到
- 在修改列表后,std :: list&lt; t&gt; :: end()的值是否会更改
- ///<评论></评论>在Visual Studio中