A
Alfonso Morra
Hi,
What is the recomended way of returning an STL container (e.g.
std::string, std::vector etc fom a function?
Is it by simply returning a local variable? (I doubt it)
std::string foo(const std::string& rhs) {
std::string var = rhs ;
var += " received" ;
return var ;
}
OR by pointer?
std::string *foo(const std::string& rhs) {
std::string *ps = new std::string() ;
*ps = rhs ;
*ps += " received" ; //not sure if this is legal
return ps ;
}
OR by reference ?
std::string &foo(const std::string& rhs) {
std::string var(rhs), &ref ;
var += " received" ;
ref = var ;
return ref ;
}
If anyone would kindly direct me to a web resource where I can readup on
this - I'd be grateful. I have googled for several hours and not really
found anything too useful. even the sgi STL site does not seem to cover
this basic info.
What is the recomended way of returning an STL container (e.g.
std::string, std::vector etc fom a function?
Is it by simply returning a local variable? (I doubt it)
std::string foo(const std::string& rhs) {
std::string var = rhs ;
var += " received" ;
return var ;
}
OR by pointer?
std::string *foo(const std::string& rhs) {
std::string *ps = new std::string() ;
*ps = rhs ;
*ps += " received" ; //not sure if this is legal
return ps ;
}
OR by reference ?
std::string &foo(const std::string& rhs) {
std::string var(rhs), &ref ;
var += " received" ;
ref = var ;
return ref ;
}
If anyone would kindly direct me to a web resource where I can readup on
this - I'd be grateful. I have googled for several hours and not really
found anything too useful. even the sgi STL site does not seem to cover
this basic info.