Guest
Hi,
I was trying to think of a good way to create a battleship game using an array of bitfields, where each point could be 1 byte and would hold all the infomation I need. My program looks like this, but will not compile. Can anyone tell me if what i'm trying to do is impossible/stupid/possible with correct syntax. Thanks.
#include
using namespace std;
struct status {
bool ship :1;
bool shot :1;
};
void init(status *coords);
int main()
{
status coords[10][10];
init(coords);
//test for correct output
cout << coords[0][0].shot << ' ' << coords[0][1].shot;
return 0;
}
void init(status *coords) {
int i, j;
for(i=0; i<10; i++)
for(j=0; j<10; j++) {
coords[j].ship = false;
coords[j].shot = false;
}
}
I was trying to think of a good way to create a battleship game using an array of bitfields, where each point could be 1 byte and would hold all the infomation I need. My program looks like this, but will not compile. Can anyone tell me if what i'm trying to do is impossible/stupid/possible with correct syntax. Thanks.
#include
using namespace std;
struct status {
bool ship :1;
bool shot :1;
};
void init(status *coords);
int main()
{
status coords[10][10];
init(coords);
//test for correct output
cout << coords[0][0].shot << ' ' << coords[0][1].shot;
return 0;
}
void init(status *coords) {
int i, j;
for(i=0; i<10; i++)
for(j=0; j<10; j++) {
coords[j].ship = false;
coords[j].shot = false;
}
}