我正在尝试做一个push_back
但是 Code::Blocks 给我一个奇怪的错误。我已经多次调试此代码,但我无法识别错误。该方法LoadFromConsole
有错误。
具体来说,当我通过线路时会发生错误m_blocks.pushback(blocks)
。我将粘贴一些课程。如果您需要更多课程来帮助我,我将粘贴其余代码。谢谢你。
class Block{
int m_left;
int m_top;
int m_right;
int m_bottom;
public:
Block();
void set_values(int,int,int,int);
void loadFromFile(ifstream*f);
void loadFromConsole(int x,int y, int z, int w);
int getValue(int side);
void print();
};
void Block::set_values(int izq,int arriba,int der,int abajo){
m_top = arriba;
m_left = izq;
m_bottom = abajo;
m_right = der;
}
class Board{
uint64_t m_timer;
int m_step;
int m_width;
int m_height;
vector<Block> m_blocks;
bool solveState(State*state);
bool isValid(State*state);
bool isValidSide(State*state,int cell,int side,int cell1,int side1);
bool isValidSideImplementation(State*state,int cell,int side,int cell1,int side1);
void printState(State*state);
public:
Board();
void loadFromFile(ifstream*file);
void loadFromConsole(int FIL, int COL);
void solve();
};
void Board::loadFromConsole(int FIL,int COL ){
m_height = FIL;
m_width = COL;
srand(time(0));
matriz = new int*[COL];
for (int i = 0; i < FIL; i++){
matriz[i] = new int[COL];
}
matriz[0][0] = rand()%8+1;
matriz[0][1] = rand()%8+1;
matriz[0][2] = rand()%8+1;
matriz[0][3] = rand()%8+1;
for (int i = 1; i < m_width; i++){
matriz[i][0] = rand()%8+1;
matriz[i][1] = matriz[i-1][2];
matriz[i][2] = rand()%8+1;
matriz[i][3] = rand()%8+1;
}
for (int j = 4; j < m_width*4; j+=4){
matriz[0][j] = matriz[0][j-1];
matriz[0][j+1] = rand()%8+1;
matriz[0][j+2] = rand()%8+1;
matriz[0][j+3] = rand()%8+1;
}
for (int i = 1; i < m_width; i++ ){
for (int j = 4; j < (m_width*4); j+=4){
matriz[i][j] = matriz[i][j-1];
matriz[i][j+1] = matriz[i-1][j+1];
matriz[i][j+2] = rand()%8+1;
matriz[i][j+3] = rand()%8+1;
}
}
for(int i=0;i<m_height;i++){
for(int j=0;j< (m_width*4);j+=4){
Block block;
block.print();
m_blocks.push_back(block);
}
}
}