this -> gamesMap.insert(pair<int, int (*)[2]>(const ¤tPos/3,const &dataArray));
我不认为,需要更多的代码,但我看不出我做错了什么在这里预计初步表达之前(
this -> gamesMap.insert(pair<int, int (*)[2]>(const ¤tPos/3,const &dataArray));
我不认为,需要更多的代码,但我看不出我做错了什么在这里预计初步表达之前(
简短的回答:
变化:
this->gamesMap.insert(pair<int, int (*)[2]>(const ¤tPos/3,const &dataArray));
到:
this->gamesMap.insert(std::pair<int, int (*)[2]>(currentPos/3, &dataArray));
这可能不太正确(正确的答案取决于dataArray的类型),并且可能会导致其他问题(例如,如果gamesMap中pair对的生命期超过dataArray的生命期,那么您将结束与一个无效的指针)。
长的答案
在这条线,你正试图调用std::pair<int, int (*)[2]>
构造:
this->gamesMap.insert(pair<int, int (*)[2]>(const ¤tPos/3,const &dataArray));
您正试图通过const ¤tPos/3
作为第一个参数和const &dataArray
作为第二论据。我不确定你在这里试图做什么,但是这些都没有语法上的错误。
//Declare `a` to be a const int
int const a(10);
//Declare `b` to be a reference to a const int
//(in this case, a reference to `a`)
int const& b(a);
//Declare `c` to be a pointer to a const int
//(in this case, the the address of `a` is used)
int const* c(&a);
const
是在所述对象的所声明的描述增加了更多的信息的声明的注释:const
只能在对象的声明,例如可以使用。当你传递参数时,参数的形式为表达式。表达式的类型可以由编译器推导出来,所以不需要额外的注释。此外,C++中没有提供这种注释的语法。
你想通过的是currentPos
除以三,地址dataArray
。
评价为“currentPos
除以3”的表述为“currentPos/3
”。
评价为“dataArray
”的地址的表述是“&dataArray
”。
这意味着(如简答),你应该写:
this->gamesMap.insert(std::pair<int, int (*)[2]>(currentPos/3, &dataArray));
对不起,我正在使用C++,和这 - >指的是inhereted类卫生组织的基本分类是一个模版,基类有一个名为gamesMap的地图,我试图将片段中显示的值插入它,但我得到了我发布的错误消息。 – Man
什么是currentPos和dataArray的数据类型 –
另外gamesMap的声明会很有用。 –