开发者

error: initializer fails to determine size of ‘K’

开发者 https://www.devze.com 2022-12-24 19:00 出处:网络
I get the error \"intitializer fails to determine size of \'K\'\"at line int K[]= new int[Vertices开发者_JAVA百科->total];

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

int K[]= new int[Vertices开发者_JAVA百科->total];

How do I solve it?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消