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 foo { get; private set; }
In C++ I have to write
private: Foo foo; public: Foo getFoo() { return foo; }
Is there some such concept in the C++11 allowing me to have some syntax sugar on this?
No, C++11 does not support ALL the features of C11. It does not even support all the features of C99. Variable-length arrays, for example, were introduced in C99, but C++ does not yet support them.
C11 (formerly C1X) is an informal name for ISO/IEC 9899:2011, a past standard for the C programming language. It replaced C99 (standard ISO/IEC 9899:1999) and has been superseded by C17 (standard ISO/IEC 9899:2018).
C11 eliminates these hacks by introducing two new datatypes with platform-independent widths: char16_t and char32_t for UTF-16 and UTF-32, respectively (UTF-8 encoding uses char, as before). C11 also provides u and U prefixes for Unicode strings, and the u8 prefix for UTF-8 encoded literals.
In C++ you can write your own features. Here is an example implementation of properties using unnamed classes. Wikipedia article
struct Foo { class { int value; public: int & operator = (const int &i) { return value = i; } operator int () const { return value; } } alpha; class { float value; public: float & operator = (const float &f) { return value = f; } operator float () const { return value; } } bravo; };
You can write your own getters & setters in place and if you want holder class member access you can extend this example code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With