Can you give me an example of declare and allocting arrays (double type)

Can you give me an example to declare managed array in Visual C++.Net Thank you very much! 

As i follow a book to decalare and allocate an double managed array (accroding to a book) as follows:


double
Q _gc[] = new double _gc[3];//line (a)

Q[] = {0.0225, 0.01, 0.0025};//Line (b)

But i get the follwing errors at line (a):
error C2146: syntax error : missing ';' before identifier '_gc'
error C2501: '_gc' : missing storage-class or type specifiers
error C2440: 'initializing' : cannot convert from 'double *' to 'int []'
error C2086: 'int _gc[]' : redefinition

Errors at Line (b)
error C2501: 'Q' : missing storage-class or type specifiers
error C2040: 'Q' : 'int []' differs in levels of indirection from 'double'

Thank you very much!










Answer this question

Can you give me an example of declare and allocting arrays (double type)

  • Candace

    It works! Thank you very much! Martin!

  • Erasure

    If you are using VS.NET 2003 with managed extension than there is another _ missing must be __gc (double underscore gc)!

  • wmertz

    AFAIK You can use this form of assignment of arrays only at initialization:

    double P __gc [] = {0.0225, 0.01, 0.0025, 0.0, 0.0625, 0.25, 1.0, 4.0, 9.0};
    Q = P;



  • SimonGray

    Thanks Martin!
    But if i changed it to

    double __gc Q[] = new double __gc[9];

    There is another error:
     error C3150: 'Q' : '__gc' can only be applied to a class, struct, interface, array or pointer

    along with the errors for Q[]. missing ; before"}"...etc.
     
    So Can you see any mistake in this programm line

    Q[] = {0.0225, 0.01, 0.0025, 0.0, 0.0625, 0.25, 1.0, 4.0, 9.0};

    Thanks!



  • rustiehatchet

    I changed to double underscore __gc,

    double Q __gc[] = new double __gc[9];

    Q[] = {0.0225, 0.01, 0.0025, 0, 0.0625, 0.25, 1.0, 4.0, 9.0};

    But i still got errors
    error C2059: syntax error : ']'
    error C2143: syntax error : missing ';' before '{'
    eoor C 2143: syntax error : missing ';' before '}'

    Can you tell me how i can correct it Thank you very much!




  • kihtap

    Should be:

    double __gc Q[] = new double __gc[9];



  • Can you give me an example of declare and allocting arrays (double type)