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


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

Re: lista inicjalizacyjna - pytanie

From Christian Gollwitzer <auriocus@gmx.de>
Newsgroups comp.lang.c++
Subject Re: lista inicjalizacyjna - pytanie
Date 2023-03-03 21:50 +0100
Organization A noiseless patient Spider
Message-ID <tttmj3$nm23$1@dont-email.me> (permalink)
References <ttt66q$2lk8d$1@portraits.wsisiz.edu.pl> <ttt9c4$md51$1@dont-email.me>

Show all headers | View raw


Am 03.03.23 um 18:05 schrieb Paavo Helde:
> 03.03.2023 18:11 Jivanmukta kirjutas:
>> Uczę się C++.
>> Jeżeli zamiast pisać:
>>
>> class C {
>> int m;
>> public:
>>      C(int v) : m(v) {}
>> };
>>
>> możemy pisać:
>>
>> class C {
>> int m;
>> public:
>>      C(int v) { m = v; }
>> };
>>
>> to po co w ogóle jest lista inicjalizacyjna w kontruktorze?
> 
> Antud näite puhul ei ole erilist vahet, mida kasutada, aga üldiselt 
> tuleks initsialiseerimiseks kasutada initsialiseerijate loendit, selle 
> jaoks on see mõeldud.

I can't read the Finish one, but the Polish question (probably 
accidentally) asks what is the difference between the initializer and 
what is it good for, if we can simply use the assignemnt.

The answer is that in some cases, there is a difference between calling 
the constructor and assigning. E.g.

std::vector<int> v(30);

vs.

std::vector<int> v;

v = ... ; // now what?

In this case it might simply be inefficient, in other cases impossible 
to assign - e.g. with a reference variable.


	Christian

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


Thread

lista inicjalizacyjna - pytanie Jivanmukta <jivanmukta@poczta.onet.pl> - 2023-03-03 17:11 +0100
  Re: lista inicjalizacyjna - pytanie Paavo Helde <eesnimi@osa.pri.ee> - 2023-03-03 19:05 +0200
    Re: lista inicjalizacyjna - pytanie Christian Gollwitzer <auriocus@gmx.de> - 2023-03-03 21:50 +0100
      Re: lista inicjalizacyjna - pytanie Muttley@dastardlyhq.com - 2023-03-04 09:52 +0000

csiph-web