簡體   English   中英

從不兼容類型&#39;value_type&#39;(aka&#39;std :: __ 1 :: vector)分配給&#39;int *&#39; <int, std::__1::allocator<int> &gt;&#39;)

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM