March 12th, 2002, 05:30 AM
return addr of an struct-array
Why doesn't this give the expected result:
Yes, I know this could be done easier with classes in C++,
/* start cpp-code */
option *getOption(char *chrOption, int intMaxOption)
myOption = new option[intMaxOption];
//code to fill myOption with elements
int main(int argc, char* argv)
myOption = getOption(test, 5);
//all values in myOption gives the same as the
//last filled value in myOption.
//ex. myOption.option2 will give the same as
//myOption.value, even if they have different
//values in the getOption function...
/* end cpp-code */
but would like to have a solusion to this problem.
March 13th, 2002, 02:16 PM
did you initialize option2 with new too on each run of your function? if not, it points to a random memory location, and you seem to have the same pointer each time, this is why you always get the last result which overwrote the one before..
this can cause all kinds of weird effects anyway...