Does C++11 have C#-style properties?

前端 未结 15 1114
伪装坚强ぢ
伪装坚强ぢ 2020-11-28 03:16

In C#, there is a nice syntax sugar for fields with getter and setter. Moreover, I like the auto-implemented properties which allow me to write

public Foo fo         


        
15条回答
  •  被撕碎了的回忆
    2020-11-28 03:48

    Maybe have a look at the property class I have assembled during the last hours: https://codereview.stackexchange.com/questions/7786/c11-feedback-on-my-approach-to-c-like-class-properties

    It allows you to have properties behaving like this:

    CTestClass myClass = CTestClass();
    
    myClass.AspectRatio = 1.4;
    myClass.Left = 20;
    myClass.Right = 80;
    myClass.AspectRatio = myClass.AspectRatio * (myClass.Right - myClass.Left);
    

提交回复
热议问题