Exception during dynamic array class pointer element creation

0

I have a class

class Container
{

Container ()
{
...
}

...

};

And double pointer as a global variable

Container **models;

In main I do the next

models = new Container*[10000];

After that call

models[0] = new Container();

And get exception:

access violation while trying to write address 0x00000000

What’s wrong?


Wrong is that in the class

class Container
{
public:
int **ar;

Container()
{
for(int i=0;i<10;i++)
ar[i]=0;
}

...

}

I forgot to initialize **ar array before initializing each *ar array. Thanks for feedback.

c++
dynamic-arrays
asked on Stack Overflow Mar 30, 2020 by Artur • edited Mar 30, 2020 by Artur

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0