<分区>
更新问题: 为什么我们有“我正在 build ”。 我在哪里可以依靠它? 我在大学读了 C++ 书,但我确实找到了。
我很抱歉,因为一些错误。
#include <vector>
#include <string>
#include <iostream>
struct President {
std::string name;
std::string country;
int year;
President(std::string p_name, std::string p_country, int p_year)
: name(std::move(p_name))
, country(std::move(p_country))
, year(p_year)
{
std::cout << "I am being constructed.\n";
}
President(President&& other)
: name(std::move(other.name))
, country(std::move(other.country))
, year(other.year)
{
std::cout << "I am being moved.\n";
}
President& operator=(const President& other) = default;
};
int main()
{
std::vector<President> reElections;
std::cout << "\npush_back:\n";
reElections.push_back(President("Franklin Delano Roosevelt", "the USA", 1936));
for (President const& president : reElections) {
std::cout << president.name << " was re-elected president of "
<< president.country << " in " << president.year << ".\n";
}
}
输出:
推回: 我正在 build 中。 我被感动了。
\n非常感谢。