#include <cstring>
#include <iostream>
class foo_t {
friend std::ostream &operator<<(std::ostream &os, foo_t const &foo) {
os << foo.data;
return os;
}
public:
foo_t(void) : data(new char[14]) { std::strcpy(data, "Hello, World!"); }
~foo_t(void) { delete[] data; }
foo_t(const foo_t& other);
foo_t &operator=(const foo_t& other);
private:
char *data;
};
foo_t::foo_t(const foo_t& other) {
std::cout << "call copy constructor!!!" << std::endl;
this->data = new char[strlen(other.data) + 1];
strcpy(this->data, other.data);
}
foo_t& foo_t::operator=(const foo_t& other) {
std::cout << "call the copy assignment operator!!!" << std::endl;
if (this == &other)
return *this;
this->data = new char[strlen(other.data) + 1];
strcpy(this->data, other.data);
return *this;
}
int main() {
foo_t foo;
std::cout << foo << '\n';
foo_t t(foo);
// foo_t t2 = t;
foo_t t3;
t3 = t;
return 0;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有