我有一个Element*的std::vector。何时调用析构函数。如果它是Element的向量,它有什么不同
std::vector<Element*> vect;
..
struct Element
{
Record *elm;
Element(Record *rec)
{
elm = new Record();
//...copy from rec
}
~Element()
{
delete elm;
}
};
我使用向量的方法如下:
Element *
正如我所理解的,成员函数末尾的const说明符意味着类的成员不能在该函数中被修改,除非它们声明为可变的。话虽如此,但我有以下几点:
mns:: list ::list是一个链表实现,它的功能不是const。
template<typename T> class HashTable{
private:
std::vector<mns::list::list<T> * > * hashtable;
long long int size;
public:
HashTable(int _size){
我已经看了很多在线文章和书籍,但我仍然无法找到答案。代码是::
#include <iostream>
#include <vector>
using namespace std;
class a
{
public :
~a()
{
cout << "destroy";
}
};
int main()
{
vector <a*> *v1 = new vector<a*>;
vector <a> *v2 = new vector<a>;
I have a function `vector_push` that pushes data to a vector like this:
void vector_push(vector *v, void *item)
{
if (v->capacity == v->size)
vector_resize(v, v->capacity * 2);
v->data[v->size++] = item;
} 这是c中一个非常标准的vector_push函数。现在,我正在尝试使用此函
我想适当地删除向量中的所有元素。我需要用下面应该看到的方式填充一个结构向量的向量,每次创建一个新的结构向量调用new方法。
这是我的代码:
struct node
{
int index;
double value;
}
struct problem
{
int l;
struct node **x;
};
struct problem prob; // set by read_problem
std::vector<node *> vettProbX;
int main(){
node tmpValue;
std::v