How to Define or Implement C# Property in ISO C++?

后端 未结 3 768
一整个雨季
一整个雨季 2021-01-27 18:09

How to Define or Implement C# Property in ISO C++ ?

Assume following C# code :

int _id;

int ID
{
    get { return _id; }
    set { _id = value; }
}
         


        
3条回答
  •  说谎
    说谎 (楼主)
    2021-01-27 18:28

    Short answer: you can't.

    Long answer: You could try to simulate them via proxy classes, but believe me this is not worth the minor incovenience in having set/get functions.

    You'd have basically to define a class which forwards all the behavior of the variable. This is insanely hard to get right, and impossible to be made generic.

提交回复
热议问题