c++ - 将参数复制到结构元素数组时,“)”标记之前的主表达式
问题描述
TimestampedConatiner.hpp:
#ifndef TIMESTAMPEDCONTAINER_HPP_
#define TIMESTAMPEDCONTAINER_HPP_
using namespace std;
#include<string>
#include <ctime>
template <class k, class d>
class timestampedContainer
{
private:
struct elements
{
k keyType;
d dataType;
string timeStamp;
};
int position;
int size;
elements * containerPtr;
public:
timestampedContainer(int);
void insertElement(k,d);
void getElement(int, k, d, string);
void deleteContainer();
~timestampedContainer();
};
template<class k, class d>
timestampedContainer<k, d>::timestampedContainer(int size)
{
position = 0;
containerPtr = new elements[size];
}
template<class k, class d>
void timestampedContainer<k, d>::insertElement(k, d)
{
if(position <= size)
{
containerPtr[position] = elements(k, d);
position++;
}
}
#endif
当我尝试将参数复制到元素结构数组中时,插入元素函数中会弹出错误。我打电话的方式有问题吗?这个错误到底是什么意思?
解决方案
表达式有两个问题elements(k, d)
。
k
并且d
是类型。因此,elements(k, d)
根本没有意义。elements
没有明确定义的构造函数。因此,您不能使用类似构造函数的调用来构造该类型的对象。
您可能想要使用类似的东西:
template<class kType, class dType>
void timestampedContainer<kType, dType>::insertElement(kType k, dType d)
{
if(position <= size)
{
containerPtr[position] = {k, d, ""};
position++;
}
}
推荐阅读
- javascript - 如果 id 与 JsonB 相同,则更新 JsonA 对象值
- json - JSON:根据匹配的键修改特定值:另一个JSON的值
- python - Pandas 通过多个字符串分隔符将列拆分为多列
- typescript - 在类型化的字符串文字中强制使用后缀
- ruby - Nokogiri:解析和更新 Plist 中的值
- php - LDAP:无法添加 CN 不包含名字和姓氏的用户
- laravel - Laravel job 工作命令不像以前那样工作
- css - 在 css 文件中导入的 css 文件序列
- git - 在 azure vm 上部署
- hadoop - flink-sql 如何处理'count(distinct)'这样的场景