return value

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jerry

    return value

    i want to return an empty SET object,i write it as "return set<string>
    temp",but there are some error when complie it,and i have told that i
    should write it as "return set<stringtemp( )",who can
    tell me why?
    thank you!
  • SG

    #2
    Re: return value

    On 6 Nov., 09:02, jerry <machel2...@yah oo.cnwrote:
    i want to return an empty SET object,i write it as "return set<string>
    temp",but there are some error when complie it,and i have told that i
    should write it as "return set<stringtemp( )",who can
    tell me why?
    thank you!
    return set<string>(); // default constructed temporary

    You should be aware of that returning containers that way may be
    expensive because all the container's entries are copied. If you don't
    want this try one of these alternatives:

    * add a function parameter: a pointer or reference to a set where
    the result should be stored into and make the function void.
    * create the set on the heap, put the pointer into a std::auto_ptr,
    and return the auto_ptr object (not very popular these days, I
    think)
    * wait for an implementation of the upcoming C++ standard
    (move semantics)

    Cheers,
    SG

    Comment

    Working...