Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: getters and setters

Reply
Thread Tools

Re: getters and setters

 
 
cookie__raver@hotmail.com
Guest
Posts: n/a
 
      06-21-2005
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Read Only attributes, auto properties and getters and setters TechieInsights Python 5 02-12-2009 06:11 PM
setters and getters in python 2.6 and 3.0 Daniel Fetchinson Python 2 11-29-2007 09:36 PM
Getters and Setters Scott.R.Lemke@gmail.com Java 7 06-10-2006 11:01 AM
Getters and Setters For Object Properties in JS 1.5 and ECMAScript Lachlan Hunt Javascript 2 03-28-2005 01:48 PM
XMLEncoder/XMLDecoder and mutable arguments to getters/setters George Armhold Java 1 09-02-2004 05:43 PM



Advertisments