if语句

时间:2016-01-31 19:44:13

标签: c++

这是我的代码,它引发了一个奇怪的错误。我google了一下,但我不知道什么是错的。错误发生在if语句的某处。 StackOverflow抱怨代码太多,但我真的不知道应该添加什么。

错误:

Game.cpp:129:73: error: no match for call to ‘(std::string {aka std::basic_string<char>}) (bool)’

代码:

bool Game::checkStartAdjacents() {
    for(int i = 0; i < this->floodedTiles.size(); i++) {
        for(int y = 0; y < 30; y++) {
            for(int x = 0; x < 30; x++) {

                Tile* candidate = this->tileMap[x][y];

                if(candidate->flooded == false 
                        && candidate->color == this->floodedTiles[i]->color (
                        (candidate->x == this->floodedTiles[i]->x 
                        && candidate->y == this->floodedTiles[i]->y - 1) // candidate is above
                        || (candidate->x == this->floodedTiles[i]->x
                        && candidate->y == this->floodedTiles[i]->y + 1) // candidate is below
                        || (candidate->y == this->floodedTiles[i]->y
                        && candidate->x == this->floodedTiles[i]->x - 1) // candidate is to the left
                        || (candidate->y == this->floodedTiles[i]->y
                        && candidate->x == this->floodedTiles[i]->x + 1))) { // THE ERROR HAPPENS AT THIS LINE

                    floodTile(candidate);
                    return true;
                }
            }
        }
    }

    return false;
}

这是Tile类:

#include <string>

#ifndef TILE_H
#define TILE_H

using namespace std;

class Tile {
public:
    Tile(string color, int x, int y);
    Tile(const Tile& orig);
    virtual ~Tile();
    string color;
    int x;
    int y;
    bool flooded;
private:

};

CPP档案

#include "Tile.h"

Tile::Tile(string color, int x, int y) {
    this->color = color;
    this->x = x;
    this->y = y;
    flooded = false;
}

Tile::Tile(const Tile& orig) {
}

Tile::~Tile() {
}

1 个答案:

答案 0 :(得分:2)

        if(candidate->flooded == false 
                && candidate->color == this->floodedTiles[i]->color && (
//                                                   forgotten this ^^            

        if(candidate->flooded == false 
                && candidate->color == this->floodedTiles[i]->color || (
//                                                          or that ^^