|
Re: kabc question: msg#00405kde.devel.pim
On Wednesday 29 May 2002 00:05, Reinhold Kainhofer wrote: > > If you use something like > > void setEmail(KABC::Addressee a, QString mail) { > a->insertEmail(mail); } > > void doSync(...) {.... > setEmail(myAddressee, "test@xxxxxxxxxx"); > setEmail( myAddressee, "test2@xxxxxxxxxxxxxxxxxx"); > } > > doesn't the by-value call to setEmail create a copy of the > myAddressee? Yes, if you pass the Addressee by value the setEmail() function will operate on a copy. That means it will not have the effect you desire, because the email address will be added in the copy which will be deleted when the function returns. It has no effect. That's exactly what you should expect as it's the same with every other type of object. Copying an addressee is, by the way, a very cheap operation because the data is not copied but only the pointer to the data. That means until you change the data in the addressee, the data is shared. That's implicit sharing (sometime also called "copy-on-write"). > (You see, my theoretical C++ knowledge is not so > profound, it's just what I remember from reading Stroustrup some long > time ago). If so, does a definition like > > void setEmail(KABC::Addressee &a, QString mail) {...} > > prevent this, since the Addressee is passed by reference? If so, with > your patch one really needs to take care to use the &a in all > methods! Not more than with every other object. If you want the function to change the object in the calling code you need a reference or a pointer. If you just want to pass the value to be used inside the function a "const Addressee &a" argument is the most appropriate. > I still think your patch is the correct and clean solution to the > problem, we just need to make sure developers understand that they > need to pass by reference if they don't want to do some unnecessary > stuff. I don't think that Addressee needs the developer to know something special. The only thing is that the class is implicityly shared which means that it's perfectly ok to pass the class by value without loosing performance. -- Cornelius Schumacher <schumacher@xxxxxxx> _______________________________________________ kde-pim mailing list kde-pim@xxxxxxxxxxxx http://mail.kde.org/mailman/listinfo/kde-pim kde-pim home page at http://pim.kde.org/ |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: kde-organizer, kde-pilot, New Question...: 00405, Adriaan de Groot |
|---|---|
| Next by Date: | Bug in Addressee: 00405, Tobias Koenig |
| Previous by Thread: | Re: kabc questioni: 00405, Reinhold Kainhofer |
| Next by Thread: | Re: kabc question: 00405, Mike Pilone |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |