它确实与 C++/CLI 有关(非托管 C++ 并没有真正的属性概念)。
属性是行为类似于字段的实体,但由 getter 和 setter 访问器函数在内部处理。它们可以是标量属性(它们的行为类似于字段)或索引属性(它们的行为类似于数组)。在旧语法中,我们必须直接在代码中指定 getter 和 setter 方法来实现属性 - 正如您可能猜到的那样,这并没有那么受欢迎。在 C++/CLI 中,语法更接近 C#,并且更易于编写和理解。
摘自本文:http://www.codeproject.com/KB/mcpp/CppCliProperties.aspx
另请参阅有关 C++/CLI 属性的MSDN 。
示例代码:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9728 次 |
| 最近记录: |