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的聲明會很有用。 –