Use of ^ operator in visual c++

…衆ロ難τιáo~ 提交于 2019-12-10 03:46:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!