gpt4 book ai didi

properties - C++/CLI 中的属性是什么?

转载 作者:行者123 更新时间:2023-12-01 01:30:56 25 4
gpt4 key购买 nike

我看到了 property在 C++ 代码中。我认为它与 C++/CLI 相关。

究竟是什么?

最佳答案

它确实连接到 C++/CLI(非托管 C++ 并没有真正的属性概念)。

Properties are entities that behave like fields but are internally handled by getter and setter accessor functions. They can be scalar properties (where they behave like a field) or indexed properties (where they behave like an array). In the old syntax, we had to specify the getter and setter methods directly in our code to implement properties - wasn't all that well received as you might guess. In C++/CLI, the syntax is more C#-ish and is easier to write and understand.



摘自本文: http://www.codeproject.com/KB/mcpp/CppCliProperties.aspx

另见 MSDN关于 C++/CLI 中的属性。

示例代码:
private:
String^ lastname;

public:
property String^ LastName
{
String^ get()
{
// return the value of the private field
return lastname;
}
void set(String^ value)
{
// store the value in the private field
lastname = value;
}
}

关于properties - C++/CLI 中的属性是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4912183/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com