簡介
該文章用于記錄學(xué)習(xí)中遇到的部分問題俄精,可能不包含具體答案改橘,會根據(jù)后續(xù)學(xué)習(xí)進行持續(xù)更新
class Bashful {
public:
Bashful() {
std::cout << "Bashful constructor" <<std::endl;
}
Bashful(const Bashful& bash) {
std::cout << "Bashful copy constructor" << std::endl;
}
Bashful& operator=(const Bashful& bash) {
std::cout << "Bashful assignment constructor" << std::endl;
return *this;
}
Bashful(Bashful&& bash) {
std::cout << "Bashful move constructor" << std::endl;
}
Bashful& operator=(Bashful&& v) {
std::cout << "Bashful assignment operator" << std::endl;
}
~Bashful() {
std::cout << "Bashful destructor" << std::endl;
}
};
int main(int argc, char** argv)
{
std::vector<Bashful> s;
s.push_back(Bashful());
Bashful bashful;
s.push_back(bashful);
return 0;
}
輸出值
Bashful constructor
Bashful move constructor
Bashful destructor
Bashful constructor
Bashful copy constructor // why
Bashful copy constructor // why
Bashful destructor // why
Bashful destructor // desturctor for bashful
Bashful destructor // destructor for s[1]
Bashful destructor // destructor for s[0]