[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: Re: strings and QStrings
From: Patrick Julien <freak () desource ! net>
Date: 2000-12-10 13:04:32
[Download RAW message or body]
On December 10, 2000 05:26 am, Christopher Willmot wrote:
> On Sun, Dec 10, 2000 at 09:29:55AM +0100, Bo Thorsen wrote:
> > Date: Sun, 10 Dec 2000 09:29:55 +0100 (MET)
> > From: Bo Thorsen <bo@sonofthor.dk>
> > To: kde-devel@master.kde.org
> > Subject: Re: strings and QStrings
> >
> > On Sun, 10 Dec 2000, David van Hoose wrote:
> > See this code: ...
>
> Ah, I thought constructors and assignment operators were semantically
> different.
They are, but in the following cases...
B b1 = a;
B b2 ( a );
these are not assignment, they are both initializers. ISO says the copy
constructors get called for init, and assignment operator get called for
assignment.
So, after construction, ...
b2 = a;
the assignment operator gets called.
>If that's the case it would surely be wrong for the compiler
> to substitute one for the other. Scott Meyers, in his (now rather old?)
> book "Effective C++" claims that the compiler has to create a temporary
> object which is then passed to the assignment operator. That would
> account for there being two contructor calls.
Not in the code that was provided, temporaries are made when conversions for
parameters are needed. Since B has a copy constructor that takes an A&, no
other constructor is called.
>
> But aren't QStrings shared? So either way is should be just a matter of
> increasing a count in the shared object.
Not in this case, it's the char * inside a string converted to const char *
being assigned to a QString.
>> Visit http://master.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic