STL 列表数组无法访问列表函数
Array of STL List not accessing List functions
我有一个列表数组:
int* adj;
std::list<int> adj[n];//where n is the size of the array
我的问题是,当我需要adj[v].size()
v 是我当前所在的索引时,我收到错误:
request for member 'size' in '((GenericClass*)this)->GenericClass::adj', which is of non-class type 'int*' for(int i=0; i<adj.size(); ++i)
对于我尝试在 STL List 类中访问的每个其他函数,我同样会遇到这个问题。我也尝试创建一个迭代器:
for(std::list<int>::iterator it=adj[v].begin(); it != adj[v].end(); ++it)
但我遇到了与之前所说的相同的问题。
编辑:在我的班级的私人中,我有:国际* 调整;
然后在我的一个函数中,在我从用户那里获得数组的大小后,我有std::list<int> adj[n]
行。
编辑2:
我现在已经把我的私人改为阅读:typedef std::list<int> IntList;
typedef std::vector<IntList> AdjVec;
AdjVec adj;
我在我的公共中有一个函数,int GenericClass::search(AdjVec adj, int v)我收到一个错误
'AdjVec' has not been declared
int search(AdjVec adj, int v);
^
GenericClass.cc:234:20: error: no matching function for call to 'GenericClass::search(GenericClass::AdjVec&, int&)'
u= search(adj, v);
您正在尝试访问int
上size()
的成员方法。
int* adj;
您已为变量 adj
重新定义(或未定义列表)。编译器认为你在谈论int* adj
而不是std::list<int> adj[n];
摆脱第一个定义并使用第二个定义。
编辑:似乎您不知道编译时n
是什么,并且adj
是您的一个类的成员。在这种情况下,只需使用vector
并在运行时动态调整其大小。
// In your header.
typedef std::list<int> IntList;
typedef std::vector<IntList> AdjVec;
AdjVec adj;
// In your cpp, when you know what 'n' is.
adj.resize(n);
adj[0].size();
- 访问类lintalizer列表中的结构元素
- 从C++中的对列表中访问特定元素
- 访问动态分配列表中的元素
- 在C++中循环访问自定义结构列表的小问题
- 访问列表中的所有 std::变体,并为每次访问捕获附加值
- 访问列表向量中的结构
- c++ 循环访问对象列表并删除对象
- 循环访问对象列表 c++
- 在 c++ 中访问列表向量时出现问题
- 在 DLL 中嵌入 Python:Py_DECREF列表对象时访问冲突读取位置
- 对C++列表的基于索引的访问
- C++娜娜 如何从全局列表框*指针访问列表框内的索引 0 上的按钮?
- 创建类型列表并访问每种类型的静态成员?
- 在为工作线程访问 lambda 中捕获的向量列表中的元素引用时,是否需要互斥锁?
- 如何合并两个双重链接列表(访问下一个链接)
- 读取访问违规当前为0xCDCDCDCD,链接列表窗口
- 能够访问逐项列表的最佳结构
- 访问链表中的结构(带有指向其子实现的指针列表的树)
- 如何在C++中访问标准::列表中的函数
- STL列表访问倒数第二个元素