> My preference is:
>
> class C{
> int x() { return _x; }
> void x(int x_) { _x = x_; }
> private:
> int _x;
>
> };
>
> But I believe I am not in the majority on this.
That's what they seem to use in the ACE libaries.
(
http://www.cs.wustl.edu/~schmidt/ACE.html)
It's not the best, of course, since it's somewhat ambiguous about whats
actually inferred by the statement.
If you're feeling brave you might want to check out STLSoft's
techniques for efficient properties for C++ (look for field properties
and method properties;
http://www.stlsoft.org). It's described in the
Properties chapter in Mathew Wilson's Imperfect C++ book. As he admist
in the book, the technique's pretty funky, but he manages to get 100%
speed efficiency, and one byte per class space efficiency. Although
it's a bit challenging to look at, it works a treat - I used it in a
code generator at work - from COM typelibs to C++ wrapper classes -
with 'normal' COM property syntax.
If you're using Borland or Visual C++, you might want to check out
their compiler extensions. They support (what Wilson calls) "Method
Properties", where accessing the property calls a getter or a setter
method. As he points out, they don't support static properties, i.e.
properties for a class rather than an instance, or "Field Properties",
where read-only or write-only access is provided to an instance. If
you're using a different compiler, or want more flexibility, check out
the STLSoft templates.
HTH
The Raver