[英]cannot convert 'std::optional<int>' to '__gnu_cxx::__alloc_traits<std::allocator<char> >::value_type {aka char}'
[英]Assigning to 'int *' from incompatible type 'value_type' (aka 'std::__1::vector<int, std::__1::allocator<int> >')
有誰知道如何調用向量指針,以便可以將其分配給整數? 以下是代碼:
void floodFillwithColor(vector<vector<int>>* M, int x, int y, int newC){
int* prevC = M[x][y];
int* newCPtr = &newC;
floodFillUtil(M, x, y, prevC, newCPtr);
};
如何調用向量指針,以便可以將其分配給整數?
您不能調用向量指針,但是可以使用間接運算符獲取對指向對象的引用,然后在該引用上應用下標運算符:
if(M)
int some_value = (*M)[x][y]; // assign to an integer
else
// handle the case where M is null
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.