- Jan 24, 2004
- 9,306
- 4
- 81
So I'm mucking around with c++ at work since I'm bored and just got vc++ installed on my machine. I'm trying to make a board for a game as practice. It compiles and when run throws System.Nullreferenceexception on line 37 of table.h line 5 of main.cpp. I know this is probably stupid, but I've never been good with c++ and just messing around to learn.
#include "Table.h"
int main()
{
Table *theTable = new Table;
theTable->consoleOutput();
return 1;
}
#include <iostream>
using namespace std;
class Table {
private:
signed short int * theTable;
unsigned short int dimensionX;
unsigned short int dimensionY;
unsigned int size;
public:
Table (int x, int y) {
theTable = new signed short int[x*y];
dimensionX = x;
dimensionY = y;
size = x*y;
emptyTable();
}
Table (int size) {
Table (size, size);
}
Table () {
Table (3,3);
}
~Table() {
delete theTable;
}
void emptyTable() {
for (unsigned int a=0; a<size; a++) {
theTable[a] = 0;
}
}
void consoleOutput() {
//for (unsigned short int i=0; i<dimensionX; i++) {
// for (unsigned short int j=0; j<dimensionY; j++){
theTable[0 /*j+i*dimensionX*/] = 1;
// }
// cout<<endl;
//}
}
};
#include "Table.h"
int main()
{
Table *theTable = new Table;
theTable->consoleOutput();
return 1;
}
#include <iostream>
using namespace std;
class Table {
private:
signed short int * theTable;
unsigned short int dimensionX;
unsigned short int dimensionY;
unsigned int size;
public:
Table (int x, int y) {
theTable = new signed short int[x*y];
dimensionX = x;
dimensionY = y;
size = x*y;
emptyTable();
}
Table (int size) {
Table (size, size);
}
Table () {
Table (3,3);
}
~Table() {
delete theTable;
}
void emptyTable() {
for (unsigned int a=0; a<size; a++) {
theTable[a] = 0;
}
}
void consoleOutput() {
//for (unsigned short int i=0; i<dimensionX; i++) {
// for (unsigned short int j=0; j<dimensionY; j++){
theTable[0 /*j+i*dimensionX*/] = 1;
// }
// cout<<endl;
//}
}
};