Re: getters and setters

Discussion in 'C++' started by cookie__raver@hotmail.com, Jun 21, 2005.

  1. Guest

    > 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
     
    , Jun 21, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. George Armhold
    Replies:
    1
    Views:
    1,465
    Chris Riesbeck
    Sep 2, 2004
  2. Getters and Setters

    , Jun 9, 2006, in forum: Java
    Replies:
    7
    Views:
    689
    Eddy Young
    Jun 10, 2006
  3. Daniel Fetchinson

    setters and getters in python 2.6 and 3.0

    Daniel Fetchinson, Nov 29, 2007, in forum: Python
    Replies:
    2
    Views:
    587
    Daniel Fetchinson
    Nov 29, 2007
  4. TechieInsights
    Replies:
    5
    Views:
    358
    josh logan
    Feb 12, 2009
  5. Lachlan Hunt
    Replies:
    2
    Views:
    159
    Lachlan Hunt
    Mar 28, 2005
Loading...

Share This Page