如何在 headers/body 中正确定义 c++/cli 中的属性
我正在尝试这样做,
property double Real;
但
double Data::ComplexNumber::Real::get() {
return _real;
}
它给出了错误。如何在头文件中声明方法然后实际实现它们?您是否在 c++/cli 中使用这种方法,或者您将采用 c#/vb.net 方式声明类并在那里实现所有内容?
I am trying to do
property double Real;
and then
double Data::ComplexNumber::Real::get() {
return _real;
}
But it is giving error. How do you go about declaring the methods in the header file and then actually implementing them? Do you use this approach in c++/cli, or you'll go the c#/vb.net way of declaring the classes and implementing right there everything?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,这似乎可行:
将以下内容放入属性定义中:
OK, this seems to work:
Put the following in the property definition:
对于具有 get 和 set 的简单属性,您可以将其单独放入类定义中:
编译器将为您整理后备存储和访问器。
For a simple property with get and set, you can just put this in the class definition on its own:
and the compiler will sort out the backing store and accessors for you.