tags:

views:

342

answers:

2

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

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

How do I solve it?

+6  A: 

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.

codaddict
Thankx its working,But can i use the same K to store arrays
smile
@shiva Almost. Arrays in c are really just pointers to blocks of memory. so, if you want to use K to manipulate an array of array of integer, the declaration would be `int K** = new int*[<count_of_subarrays];´In the following , you would have to initialize each element of K with `K[i] = new int[<count_of_values>´
sum1stolemyname
+2  A: 

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

aJ