Pergunta

I'm trying to make a floodfill algorithm in C++, so my plan was to make an 2D array, and then each item would be an object, with property's to check for walls around it.

I note walls the following way, 1 = top 2 = right 4 = bottem 8 = left

so 13 would mean, top/bottem/left wall

but when i use std::bitset<sizeof(int)> bits(w); i get a "expected ';' before '(' token How do i fix this? I've tried many things but it just won't work.

My code:

// een simpele floodfill

#include <stdlib.h>
#include <iostream>
#include <bitset>

class Hokjes {
  int x;
  int y;
  int w;



public:
  void  setX(int i) { x = i;      }
  void  setY(int i) { y = i;      }
  void  setW(int i) { w = i;      }
  int   getX()      { return x;   }
  int   getY()      { return y;   }
  int   getVal()    { return x*y; }
  std::bitset<sizeof(int)>   bits(w);   // error happens in this line

  /* FreeSpace? */
  bool  Left()      { 
                      if (bits[3]) return false;
                      return true; }
  bool  Bottum()    {
                      if (bits[2]) return false;
                      return true; }
  bool  Right()     {
                      if (bits[1]) return false;
                      return true; }
  bool  Top()       {
                      if (bits[0]) return false;
                      return true; }           

};

int main() {
using namespace std;

int NrKamers;

std::cin >> NrKamers;

for (int i = 0; i<NrKamers; i++){

    int SizeX;
    int SizeY;
    Hokjes veld[SizeY][SizeX];

    std::cin >> SizeY >> SizeX;

    for (int Yas = 0; Yas <= SizeY; Yas++){
        for (int Xas = 0; Xas <= SizeX; Xas++){
            veld[Yas][Xas].setW((Yas+1)*Xas)
            veld[Yas][Xas].setX(Xas);
            veld[Yas][Xas].setY(Yas);
            std::cout << veld[Yas][Xas].Top() << std::endl;
        }
    }

    std::cout << SizeY << " " << SizeX;
}    


std::cout << NrKamers << std::endl;


system("pause");
return 0;

}

Nenhuma solução correta

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top