C 11 中的屬性
C#:
<code class="csharp">public Foo foo { get; private set; }</code>
<code class="cpp">private: Foo foo; public: Foo getFoo() { return foo; }</code>
C :
<code class="cpp">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; };</code>
<code class="cpp">Foo foo; foo.alpha = 10; // Equivalent to foo.setAlpha(10) int i = foo.alpha; // Equivalent to foo.getAlpha()</code>
以上是如何使用語法糖在 C 11 中實現屬性?的詳細內容。更多資訊請關注PHP中文網其他相關文章!