Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: initializer fails to determine size of ‘K’

Tags:

c++

I get the error "intitializer fails to determine size of 'K'"at line

int K[]= new int[Vertices->total];

How do I solve it?

like image 297
smile Avatar asked Mar 29 '10 07:03

smile


2 Answers

Change

int K[]= new int[Vertices->total]; 

to

int *K = new int[Vertices->total];

The 1st one is the Java way of creating an array, where you K is a reference to an integer array. But in C++ we need to make K a pointer to integer type.

like image 172
codaddict Avatar answered Sep 20 '22 14:09

codaddict


new int[Vertices->total] returns a pointer and hence, int *K = new int[Vertices->total]; should work fine.

If you know the size of Vertices->total at compile time ( ie CONSTANT) then you could have used int K[Vertices->total]; // Allocates the memory on stack

like image 22
aJ. Avatar answered Sep 16 '22 14:09

aJ.