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


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

Re: advice -- temp var for constructors?

From Miles Bader <miles@gnu.org>
Newsgroups comp.lang.c++
Subject Re: advice -- temp var for constructors?
Date 2011-05-20 17:50 +0900
Organization NEC Electronics
Message-ID <buo1uztwyab.fsf@dhlpc061.dev.necel.com> (permalink)
References <buo1uzuxa3i.fsf@dhlpc061.dev.necel.com> <ir59b3$2lh6$1@news.ett.com.ua>

Show all headers | View raw


"Balog Pal" <pasa@lib.hu> writes:
>> Inside a class constructor, I often wish I could use temporary
>> intermediate while calculating the initialization values -- both for
>> clarity and efficiency -- but there doesn't seem to be any reallly good
>> way to do this.
>
> Hm? Call a function that returns what you want, calculated any complex
> way you like... You can make it a private static in the class. You can
> even make it non-static, but then be extremely careful to use only
> members that are already constucted, and spam comments in the class to
> avoid reordering.

The problem with that is that multiple data members are initialized from
the _same_ set of temporaries (maybe I should have stated this more
explicitly) -- if it's only a single data member, I do indeed just use a
function, and that of course works fine.

-Miles

-- 
Future, n. That period of time in which our affairs prosper, our friends
are true and our happiness is assured.

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


Thread

advice -- temp var for constructors? Miles Bader <miles@gnu.org> - 2011-05-20 13:35 +0900
  Re: advice -- temp var for constructors? "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-05-20 07:16 +0200
  Re: advice -- temp var for constructors? "Balog Pal" <pasa@lib.hu> - 2011-05-20 10:38 +0200
    Re: advice -- temp var for constructors? Miles Bader <miles@gnu.org> - 2011-05-20 17:50 +0900
      Re: advice -- temp var for constructors? "Balog Pal" <pasa@lib.hu> - 2011-05-20 11:12 +0200
  Re: advice -- temp var for constructors? Marc <marc.glisse@gmail.com> - 2011-05-20 10:23 +0000
    Re: advice -- temp var for constructors? "Balog Pal" <pasa@lib.hu> - 2011-05-20 13:02 +0200
      Re: advice -- temp var for constructors? Marc <marc.glisse@gmail.com> - 2011-05-20 13:55 +0000
        Re: advice -- temp var for constructors? Marc <marc.glisse@gmail.com> - 2011-05-20 14:28 +0000

csiph-web