Weirderror

when I compile my code i get this weird error.
bash: line 12: 7202 Segmentation fault $file.o $args
And this error is different to any of c++ error I have encountered because of the way this is written.
And as an extra little thing could you critique my code and tell me things I could do better?
Here is the code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
 #include <iostream>
#include <ctime>
#include <random>
#include "Board.h"
#include "Board.hpp"
using namespace std;





int main() {
    Board tictactoeBoard;
    cout << "Please enter the dimesions of the board." << endl;
    tictactoeBoard.init();
    cout << "Please enter the same exact number" << endl;
    tictactoeBoard.printBoard();
    
    return 0;
}

Board.h

#include <iostream>
#include <ctime>
#include <random>
#pragma once
using namespace std;

class Board {
    public:
    Board();
    void init(); 
    void printBoard();     
    private:
    int sizeY;
    int sizeX;
    char board[NULL][NULL];    
};

Board.hpp

#include <iostream>
#include <ctime>
#include <random>
#include "Board.h"
using namespace std;

Board::Board() {
    Board();
}
void Board::init() {
        
        cin >> sizeY;
        
        cin >> sizeX;
        Board();
        board[sizeY][sizeX];
        for (int y = 0; y < sizeY; y++) {
            for (int x = 0; x < sizeX; x++) {
                if ((x % 2) == 0) {
                    char emptySpot = '.';
                    board[y][x] = emptySpot;
                }
                else {
                    char wallBetweenSpots = '|';
                    board[y][x] = wallBetweenSpots;
                }
            } 
        }
}
void Board::printBoard() {
        cin >> sizeY;
        cin >> sizeX;
        board[sizeY][sizeX];
        Board();
        for (int y = 0; y < sizeY; y++) {
            for (int x = 0; x < sizeX; x++) {
                cout << board[y][x];
            }
            cout << endl;
        }    
    
}    

Thanks!
closed account (48T7M4Gy)
In general terms this error often occurs when you're reading data out of the bounds of memory, particularly an array. At least that's where you could start looking.

Line 38 appears to be worthy of closer examination. What is the purpose? You can't declare a board dynamically the way you're going about it. Maybe just try your program where the size of the board is hard coded then work from there.
Topic archived. No new replies allowed.