C ++ / CLI:为什么我不能通过引用传递字符串? [英] C++/CLI : Why can't I pass Strings by reference?

查看:176
本文介绍了C ++ / CLI:为什么我不能通过引用传递字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么Microsoft的C ++ / CLI不允许我通过引用传递字符串?我收到以下错误:



C3699:'&':不能在类型System :: String上使用此间接

托管 C ++,这是一个与.NET Framework一起使用的混蛋C ++。



在Managed C ++中,我相信你正在寻找的语法是 System :: String ^ 。这样做的原因是,由于托管类型是由.NET Framework垃圾回收,您不允许创建常规引用,因为GC需要跟踪特定变量的所有引用,以了解何时可以安全地释放它。


Why doesn't Microsoft's C++/CLI allow me to pass strings by reference? I received the following error:

C3699: '&': cannot use this indirection on type 'System::String'

解决方案

Sounds like you are using Managed C++, which is a bastardised C++ used with the .NET Framework.

in Managed C++, I believe the syntax you are looking for is System::String^. The reason for this is that since managed types are garbage collected by .NET Framework, you aren't allowed to create 'regular' references since the GC needs to track all the references to a specific variable to know when it is safe to free it.

这篇关于C ++ / CLI:为什么我不能通过引用传递字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆