I have a function call
class MyClass {
static std::string getName(void) {
return getMyName(void); // Returning by value as well
}
};
Now if I use this function in constructor of a class
class AnotherClass {
public:
AnotherClass(void) :
m_name(std::move(MyClass::getName())) {} // 1. std::move used
const std::string& name(void) const { // 2. Should I use std::string&& (without consts)
// .... but I also need to make sure value cannot be changed (e.g, name() = "blah";)
// if std::string&& will be used should I use it simply by calling name() to call function using move or should I leave it as is?
return m_name;
}
private:
std::string m_name;
}
Is this correct usage of move semantics? How can I ensure a function is using move semantics?
I am trying to learn to implement efficiency by move semantics so apology if its dumb question.
I have checked
http://www.cprogramming.com/c++11/rvalue-references-and-move-semantics-in-c++11.html
Is this correct usage of C++ 'move' semantics?
a great explanation but need clarafication on ensuring if function is using move semantics.