如果有人有任何好的想法,那就太棒了。发布以下代码和错误消息,
源代码,
class Foo {
public:
Foo(const string& name, double score);
Foo(const Foo& other);
Foo(Foo&& other);
const string& name() const { return name_; }
double score() const { return score_; }
private:
string name_;
double score_;
};
Foo::Foo(const string& name, double score)
: name_(name), score_(score) {}
Foo::Foo(
const Foo& other) {
name_ = other.name();
score_ = other.score();
}
Foo::Foo(Foo&& other)
: name_(std::move(other.name())), score_(std::move(other.score())) {}
std::vector<Foo> students;
students.emplace_back("name1", 1.0);
students.emplace_back("name2", 2.0);
students.resize(1);
错误消息,
no matching constructor for initialization of 'Foo'
{ ::new(static_cast<void*>(__p)) _T1(std::forward<_Args>(__args)...); }