array problem

i don't know why below code occur error :"uninitialized local variable 'add' used" at line 11

actually i have initialize add as a double array~ ~

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
using namespace std;

# define happy__declspec (dllexport)

happy int __stdcall passV(bool Do_SL,double XP[12],double Support[3] ); // declare passV is exist in my dll
happy int __stdcall passV(bool Do_SL,double XP[12],double Support[3] )
{
  double add[12] ; 
 add[12] = 0  ,-4  , -5 , -6 ,-9 ,-12, -16,-31  ,-32  ,-34 ,-37  ;

  double test98 = add[2] ; // test98 should be -5
}

it is part of my code , but i think it's aleady give you enough hints to tell what/where the mistake is~ ~
 


and i don't know why tutorial teach
add[12] = { 0 ,-4 , -5 , -6 ,-9 ,-12, -16,-31 ,-32 ,-34 ,-37 };

but it occur an compile error , except i eliminate{ }

Last edited on
1
2
 double add[12] ; 
add[12] = 0  ,-4  , -5 , -6 ,-9 ,-12, -16,-31  ,-32  ,-34 ,-37  ;
Will set the 13th element (which doesn't exists) to -37, the way using braces work only as initialization, not as assignment:
double add[12] = { 0 ,-4 , -5 , -6 ,-9 ,-12, -16,-31 ,-32 ,-34 ,-37 };
thanks~ ~

how about the first question, why does
 
double test98 = add[2] ; 


is wrong?? --> :"uninitialized local variable 'add' used"

, don't i initial add at formal parameter?

how do i give add[2]'s value --> test98?
Last edited on
double test98 = add[2] ; This is right, once you have initialized properly the array you shouldn't get errors
Topic archived. No new replies allowed.