Forum Replies Created
-
AuthorPosts
-
::
Thank you very much for your response Kuci. May I ask what do you mean with lifetime of the object/variable you are returning the const& from? (I’m a beginner). Could it be that if I have something like:
std::function<const std::string&(const std::string&)> func = [](const std::string& a){return a;}; void print{ auto myValue = func(const std::string& a); } // myValue is dead here, isn't it? but any other local variable would be also dead...
Many thanks in advance!
::Thanks! That’s the correct code. The incorrect one would be to replace the piece:
friend MyDistance operator *(double m, const MyDistance& b){
return MyDistance(m*b.m);
}by (my incorrect attempt):
friend MyDistance operator *(double n, const MyDistance& b){ // const double& n
return MyDistance(n*b.m);
} -
AuthorPosts