Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #67899

Re: About getters/setters

Subject Re: About getters/setters
Newsgroups comp.lang.c++
References <kSg7F.32840$Xs5.970@fx06.am4> <86y2zk26ps.fsf@mailhub.linuxsc.com>
From JiiPee <no@notvalid.com>
Message-ID <SqL7F.98411$WI2.78457@fx34.am4> (permalink)
Organization virginmedia.com
Date 2019-08-23 07:09 +0100

Show all headers | View raw


On 22/08/2019 23:09, Tim Rentsch wrote:
> (Incidentally I am ignoring the "age/birthday" matter
> that some other people have commented on, and assuming your
> question is meant as generic, with 'age' being merely an
> unfortunate choice of example.)


correct. the example given might not have been the best. general 
question about all situations.


>
> I suggest however a slightly different pattern than (1), along
> these lines (disclaimer: not compiled):
>
>      class Person {
>          unsigned siblings_;
>          // ... other data members ...
>
>        public:
>          // ... other member functions
>
>                unsigned &siblings()       { return siblings_; }
>          const unsigned &siblings() const { return siblings_; }
>      };
>
> Now our accessor functions look more like data member access, but
> they remain functions:
>
>      if(  fred.siblings() > 0  )  ...
>
>      fred.siblings() += 1;  // a new birth in fred's family
>
> To me this pattern reads nicer on the client side than set/get
> functions.


yes many seems to suggest this online


Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

About getters/setters JiiPee <no@notvalid.com> - 2019-08-21 20:22 +0100
  Re: About getters/setters Jorgen Grahn <grahn+nntp@snipabacken.se> - 2019-08-21 19:34 +0000
  Re: About getters/setters Bo Persson <bo@bo-persson.se> - 2019-08-21 21:40 +0200
  Re: About getters/setters Öö Tiib <ootiib@hot.ee> - 2019-08-21 12:52 -0700
    Re: About getters/setters JiiPee <no@notvalid.com> - 2019-08-22 15:25 +0100
      Re: About getters/setters Öö Tiib <ootiib@hot.ee> - 2019-08-22 09:06 -0700
        Re: About getters/setters Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-08-24 04:32 -0700
  Re: About getters/setters Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-08-22 15:09 -0700
    Re: About getters/setters Ian Collins <ian-news@hotmail.com> - 2019-08-23 16:17 +1200
      Re: About getters/setters Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-08-23 05:26 -0700
      Re: About getters/setters Melzzzzz <Melzzzzz@zzzzz.com> - 2019-08-23 18:07 +0000
    Re: About getters/setters JiiPee <no@notvalid.com> - 2019-08-23 07:09 +0100
  Re: About getters/setters JiiPee <no@notvalid.com> - 2019-08-23 07:13 +0100
    Re: About getters/setters David Brown <david.brown@hesbynett.no> - 2019-08-23 09:30 +0200
      Re: About getters/setters Jorgen Grahn <grahn+nntp@snipabacken.se> - 2019-08-25 06:16 +0000
        Re: About getters/setters David Brown <david.brown@hesbynett.no> - 2019-08-25 12:12 +0200
  Re: About getters/setters Jorgen Grahn <grahn+nntp@snipabacken.se> - 2019-08-23 11:24 +0000
    Re: About getters/setters James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-08-23 08:34 -0400
      Re: About getters/setters Jorgen Grahn <grahn+nntp@snipabacken.se> - 2019-08-23 14:48 +0000
      Re: About getters/setters Jorgen Grahn <grahn+nntp@snipabacken.se> - 2019-08-23 15:49 +0000

csiph-web