Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simply 2d array error-c++

Tags:

c++

arrays

I define an array called "matriu":

#include "CQix.h"
#include "Graphics_Console.h"


class cTauler
{

CQix Qix;
HANDLE hScreen;
int iniciX, iniciY, fiX, fiY;

private:
bool matriu[38][28];

int area_activa;

};

And I want to initialize all values to false:

void cTauler::InicialitzarTauler()
{

int i,j;


for(i=0;i<=fiX+2;i++)
{
    for(j=0;i<=fiY+2;j++)
    {
        matriu[i][j]=false;
    }
}

But when I compile i get this error: 0xC0000005: Access violation.

So i tried to define the array doing this:

bool matriu[38][28]= {false};

And I can't compile because: "not allowing data member initializer"

What can I do? Thanks.

like image 223
user2238244 Avatar asked Mar 04 '26 00:03

user2238244


1 Answers

If the data matriu[38][28] is going to be always the same size, consider creating const static classmembers fiX and fiY and initialize them to values 38 and 28. You have probably not initialized them correctly...

like image 68
Kupto Avatar answered Mar 06 '26 13:03

Kupto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!