0

Are there get and set methods for protected members of a class in C++/CLI like in this example for C#?

private List<string> _myClassMember = null;

public List<string> MyClassMember
{
    get { return _myClassMember; }
    set { _myClassMember = value; }
}
4

1 回答 1

0

是的。您可以在 C++/CLI 中创建一个属性,该属性的行为就像您问题中的 C# 属性一样。

ref class MyClass
{
private:
  List<String^>^ _myClassMember = nullptr;

public:
  property List<String^>^ MyClassMember
  {
    List<String^>^ get() { return _myClassMember; }
    void set(List<String^>^ value) { _myClassMember = value; }
  }
};
于 2015-03-20T19:54:54.567 回答