[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: object-model: Return by value, reference or pointer? (or something else?)

From: Hyrum K. Wright <hyrum_wright_at_mail.utexas.edu>
Date: Tue, 12 Oct 2010 15:30:51 -0500

On Tue, Oct 12, 2010 at 2:40 PM, Branko Čibej <brane_at_xbc.nu> wrote:
>  On 12.10.2010 20:35, Hyrum K. Wright wrote:
>> 1) Return everything by value
>>    Pros: simpler memory management, less overhead (?)
>>    Cons: doesn't allow the return of NULL values, need to establish
>> conventions to represent NULL objects (an isNull() method?)
>
> Meh.
>
>    inline operator bool() const { return (this->c_struct_pointer != 0); }

That works great for our own types, but what about stuff like std::string?

inline std::string getAuthor() const { return std::string(ptr->author); }

doesn't go over so well when ptr->author is NULL. If returning by
value, we *have* to return a string, but there just isn't any way to
indicate the null string.

-Hyrum
Received on 2010-10-12 22:31:30 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.