【发布时间】:2018-08-28 18:16:17
【问题描述】:
private:
struct info{
int size = 0;
int key = 0;
int capacity = 1;
std::vector<int*> *value = new std::vector<int*>(capacity);
};
int keyCapacity_;
int size_;
std::vector<info*> *keys_;
在函数内...
//some code
keys_ = new std::vector<info*>(keyCapacity_);
//some code
(*keys_)[size_] = new info;
(*keys_)[size_]->(*value)[size] = inputValue; //getting error on this line
(*keys_)[size_]->size += 1;
(*keys_)[size_]->key = key;
我有一个指向结构信息向量的指针。然后在 info 中有一个指向将保存值的向量的指针。可能会输入大量数据,并且程序会根据需要调整向量的大小。当前输入值被添加到向量上的第一个开放点,即 size_。在我上面确定的行中,我收到了一个错误:
a3.hpp:67:20: error: expected unqualified-id before ‘(’ token
(*keys_)[size_]->(*value)[size] = value;
^
a3.hpp:67:22: error: invalid type argument of unary ‘*’ (have ‘int’)
(*keys_)[size_]->(*value)[size] = value;
如何访问该向量来更改值?
【问题讨论】:
标签: c++ pointers vector struct