title: Portability of Native C++ properties
body: <p>In Visual Studio, there is <a href="http://msdn.microsoft.com/en-us/library/yhfk0thd.aspx"><code>__declspec(property)</code></a> which creates properties similar to C#.  Borland C++ offers the <code>__property</code> keyword with the exact same functionality.  In the C++0x, there is mention of a <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1611.pdf"><code>implicit</code></a> keyword  that could be expanded to implement the same functionality.  But it didn't make it into the spec.</p>
  
  <p>I am looking for a portable and relatively clean method of declaring syntactically sugared properties that will compile in the latest compilers for Windows, OSX and Linux.  I am not concerned with compiler compatibility, just one compiler per platform.</p>
  
  <p>I am not looking for alternatives to properties that require parenthesis to get or set the property, such as overloaded methods separating the getters and setters.</p>
  
  <p>Here is an ideal usage which compiles in Visual Studio 2010:</p>
  
  <pre><code>#define _property(_type, _name, _get, _put) __declspec(property(get=_get, put=_put)) _type _name
  #define _property_readonly(_type, _name, _get) __declspec(property(get=_get)) _type _name
  
  class Window
  {
  public:
      _property_readonly(void*, Handle, GetHandle);
      _property(bool, Visible, GetVisible, SetVisible);
  
      void* GetHandle();
      bool GetVisible();
      void SetVisible(bool);
  }
  
  void main()
  {
      Window MainWindow;
      if (!MainWindow.Visible)
          MainWindow.Visible = true;
  }
  </code></pre>