我希望在已知位置插入c ++向量.我知道c ++库有一个insert()函数,它接受一个位置和要插入的对象,但位置类型是一个迭代器.我想插入到矢量中,就像我将使用特定索引插入到数组中一样.
我写;
Element element=new Element;
Run Code Online (Sandbox Code Playgroud)
我收到了错误;
homework.cpp: In function 'int main(int, char**)':
homework.cpp:227:29: error: conversion from 'Element*' to non-scalar type 'Element' requested
*** 1 errors, 0 warnings
Run Code Online (Sandbox Code Playgroud)
我不想要指针或元素数组,
我应该写一下Element *element= new Element;.有人解释一下吗?
编辑:
元素类:
class Element{
public:
Element():exists(false){};
std::string name;
std::string full_path_name;
ElementType element_type;
long element_size;
bool exists;
};
Run Code Online (Sandbox Code Playgroud)