Please help me!
-
Hi, I want to create run-time array for example I want to set the number of elements in run-Time: /**********************/ If i=0 then CClass cls[j]; else CClass cls[b]; /************************/ Best Wishes, Thanks.
you will not be allowed to do this by the compiler. you'll have to allocate the memory for your array dynamically, on the heap :
CClass cls* = new CClass[j];
be sure that j is well defined, and non-negative ! another thing :
If i=0 Then
must be traduced in C/C++ by
if (i == 0) {
that means, be careful of the
**( )**
between the condition statement, and**==**
for the equal operator (**=**
is the affectation operator). cheers,
TOXCCT >>> GEII power
[toxcct][VisualCalc] -
Hi, I want to create run-time array for example I want to set the number of elements in run-Time: /**********************/ If i=0 then CClass cls[j]; else CClass cls[b]; /************************/ Best Wishes, Thanks.
Heres your solution CClass* cls; if (i==0) cls = new CClass[j]; else cls = new CClass[b]; Rahim Rattani Software Engineer, Matrix Systems (Pvt) Ltd., Karachi - Pakistan
-
Hi, I want to create run-time array for example I want to set the number of elements in run-Time: /**********************/ If i=0 then CClass cls[j]; else CClass cls[b]; /************************/ Best Wishes, Thanks.
And to complement the previous responses, don't forget to free the memory after having used it:
if (cls) { delete[] cls; cls = NULL; }
-
And to complement the previous responses, don't forget to free the memory after having used it:
if (cls) { delete[] cls; cls = NULL; }