編輯:簡單的錯誤我看了一下,並沒有想到。忽略:)爲什麼我的乘法被視爲一個指針?
我的代碼帶來了錯誤:
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;
對不起,只是一個初學者!
我們可以看到'mapRows'和'width'的聲明嗎? – Shoe 2014-10-11 10:54:22
我們需要mapRows的類型,所以我們也需要看到'levelMap'的聲明。但它似乎是一個集合,所以你可能想嘗試'mapRows.size()* width' – PeterT 2014-10-11 10:58:02
很明顯,無論mapRows是指什麼,都沒有重載二進制乘法運算符。請參閱我的[這個常見問題解答](http://stackoverflow.com/a/3350710/140719)以瞭解何時'*'意味着取消引用以及何時表示乘法。 (請參閱[本條目](http://stackoverflow.com/a/4421719/140719)(請參閱「二進制算術運算符」)如何超載運算符。) – sbi 2014-10-11 10:58:49