【发布时间】:2014-04-01 00:07:15
【问题描述】:
我有一个列表数组:
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)
但我遇到的问题与之前所说的相同。
编辑:在我的课堂上,我有: int* adj;
然后在我的一个函数中,在我从用户那里获得数组的大小后,我有
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* adj;?为什么你还有那个? -
"我有一个列表数组:" 你有一个重复的标识符编译错误。我会先解决这个问题。
adj被多次定义。 -
“列表数组:”你能显示所提到的数据结构的完整声明吗?