问题
I am doing Visual c++ programming, I have created a CLR console application. I have noticed that String arrays should be declared like String ^, not String[]. What is the use of ^? And why is it being used instead of []? And is this substitution limited only to CLR applications? Here is a line of the code and the error:
array<String[]>[] abc;
the errors generated were
error C2143: syntax error : missing ';' before '['
error C2146: syntax error : missing ';' before identifier 'abc'
eror C2065: 'abc' : undeclared identifier
回答1:
The circumflex accent means that the object is a managed pointer,it'll be automatically collected by the Garbage Collector - you don't need to do this implicitly. Please take a look at this article to understand how arrays work in C++/CLI.
In your case:
array<String^> ^abc;
And is this substitution limited only to CLR applications?
Yes.
来源:https://stackoverflow.com/questions/10578052/use-of-operator-in-visual-c