假设我有以下两类:应该在构造函数链中使用移动语义吗?
class Person
{
public:
Person(string name, string surname)
: _name(move(name)), _surname(move(surname)) { }
...
private:
string _name;
string _surname;
};
class Student : public Person
{
public:
Student(string name, string surname, Schedule schedule)
: Person(move(name), move(surname)), _schedule(move(schedule)) { }
...
private:
Schedule _schedule;
};
int main()
{
Student s("Test", "Subject", Schedule(...));
...
return 0;
}
那是移动语义的一个很好的使用情况?正如你所看到的,在Student构造函数中有一层'move-s'。是否可以避免move
函数调用开销而不使用const
引用将参数转发给基础构造函数?
或者perhaps..should我使用常量引用每当我需要的参数转发给基构造函数?
来自Going Native 2012的OP良好视频 - [STL11:Magic && Secrets](http://channel9.msdn.com)/Events/GoingNative/GoingNative-2012/STL11-Magic-Secrets) - 请看33:45分数值与参考值的传递。 – 2013-03-16 14:18:18
@CaptainObvlious会做。谢谢。 – 2013-03-17 12:25:00