0
我明白这是一个常见问题,但我仍然设法找到解决方案。指针和结构数组
我已创建称为位置 路径location[numLevels*levelSize];
我也使用的称为起始路径堆栈一个结构路径的阵列。
问题是将数组中的正确位置传递给函数,让它创建一个放入数组的新路径,然后将其发回。
bool moveLocationStack(const vector <vector<path> > &spaceStation,const int x,const int y,path *square){
char c=spaceStation.at(y).at(x).type;
if(c!='#'){
if(!spaceStation.at(y).at(x).visit and !spaceStation.at(y).at(x).inPath)
square->type=spaceStation.at(y).at(x).type;
square->type=spaceStation.at(y).at(x).visit;
square->type=spaceStation.at(y).at(x).inPath;
square->type=spaceStation.at(y).at(x).level;
return 1;
}
return 0;
}
指针方应指向由函数调用 发送给它的数组的下一个位置,我尽量做到:
if(moveLocationStack(spaceStation,possibleX,possibleY,location[currentLocation])){
}
它有发送特定阵列部分我的问题希望指向代码currentLocation中其他位置的变量索引。如果我只写了它的位置,但我很确定它不会指向数组中的下一个可用空间,即使我增加currentLocations也是如此。
任何方式来解释这个,所以我可以理解错误?
是的,我绝对意味着当加载广场,我不知道为什么我只是写了。好的谢谢!!所以当我立即设置一个变量等于一个指针,如int * temp;如果要访问它,我会设置它等于一个变量int * temp =&num1 –
如果'num1'是一个'int',那么'int * temp = &num1;'是正确的。 – john
如果我想将整个数组作为参数传递以防万一需要多条路径进行访问,该怎么办? –