我无法在其他地方找到答案,所以我想我只需要问这个:我正在尝试获取向量(其中存储 int 指针)的别名,如下所示:
void conversion(Engine * ENGINES)
{//The Engine class has a vector of int* as a public data member called SITE
for (int i = 0; i < 3; i++)
{
vector <int*>* current = &(ENGINES[i].SITE);//the problematic line
int j_max = current -> size();
cout << j_max << endl;
for (int j = 0; j < j_max; j++)
{
for (int k = 0; k < 3; k++)
{
if (*current[j][k] == 2)
*current[j][k] = 1;
if (*current[j][k] == -1)
*current[j][k] = 0;
}
}
}
}
问题是 *current[a][b] 的索引似乎存在反转。我希望能够使用 current 作为法线向量,但现在索引与以下内容相比是相反的:
vector <int*> current1 = ENGINES[1].SITE;
so that *current[i][j] = current1[j][i]
因为某些原因。我的语法有错误吗?
我相信你的问题是[]
优先级高于一元*
。所以你得到了*(current[j][k])
代替(*current)[j][k]
,这就是你想要的。
但是,您可以通过仅采用引用而不是指针来消除该问题:
vector <int*>& current = (ENGINES[i].SITE);
然后删除你的额外负载*
运营商访问current
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)