2014-10-11 86 views
-1

編輯:簡單的錯誤我看了一下,並沒有想到。忽略:)爲什麼我的乘法被視爲一個指針?

我的代碼帶來了錯誤:

no match for 'operator*' in 'mapRows * width' 

上的代碼

// get the current tile number 
    int tileNumber = levelMap[mapRows*width + currentTile]; 

聲明在:寬

for (auto& mapRows : levelMap) 
     for (auto& currentTile : mapRows) //It loops through the rows, then goes through all the tiles in that column. 
     { 

和:

bool Map::load(const std::string& tileset, sf::Vector2u tileSize, unsigned int width, unsigned int height) 

和levelMap在:

std::vector<std::vector<Tile>> levelMap; 

對不起,只是一個初學者!

+4

我們可以看到'mapRows'和'width'的聲明嗎? – Shoe 2014-10-11 10:54:22

+2

我們需要mapRows的類型,所以我們也需要看到'levelMap'的聲明。但它似乎是一個集合,所以你可能想嘗試'mapRows.size()* width' – PeterT 2014-10-11 10:58:02

+1

很明顯,無論mapRows是指什麼,都沒有重載二進制乘法運算符。請參閱我的[這個常見問題解答](http://stackoverflow.com/a/3350710/140719)以瞭解何時'*'意味着取消引用以及何時表示乘法。 (請參閱[本條目](http://stackoverflow.com/a/4421719/140719)(請參閱「二進制算術運算符」)如何超載運算符。) – sbi 2014-10-11 10:58:49

回答

2

mapRows看起來是std::vector<Tile>,其中乘以int沒有意義。這就是錯誤告訴你的。

+0

對不起,這是愚蠢的,你是正確的。 :) – 5Mixer 2014-10-11 11:03:19

+0

老實說,我甚至不知道如何解決這個問題,因爲我不知道你想用'operator *'做什麼。與'mapRows'或'levelMap'沒有任何關係的地方''operator *'是有意義的。 – Shoe 2014-10-11 11:03:35

+0

@sbi:在2D遊戲編程中,通常會調用位圖貼圖的2d網格,其中的角色移動地圖。 – 2014-10-11 11:06:28

相關問題