您的位置:首页 > 科技 > 能源 > 个人自媒体有哪些平台_网销怎么找客户_网站seo优化方法_搜狗快速收录方法

个人自媒体有哪些平台_网销怎么找客户_网站seo优化方法_搜狗快速收录方法

2024/12/24 7:56:28 来源:https://blog.csdn.net/yk41000/article/details/144486336  浏览:    关键词:个人自媒体有哪些平台_网销怎么找客户_网站seo优化方法_搜狗快速收录方法
个人自媒体有哪些平台_网销怎么找客户_网站seo优化方法_搜狗快速收录方法

#include <iostream>
using namespace std;//父类class Father
{int age;public:double money;int *f;void show_add();//无参构造Father():f(new int (0)){}//有参构造Father(int age,double money,int f,string name):age(age),money(money),f(new int (f)),name(name){}Father(double money,int f,string name):money(money),f(new int (f)),name(name){}//拷贝构造Father(const Father &other):age(other.age),money(other.money),f(new int (*(other.f))),name(other.name){}~Father(){delete f;}// = 运算符重载Father &operator=(const Father &other);// + 运算符重载Father operator+(const Father &other);// << 运算符重载friend ostream &operator<<(ostream &out,const Father &f1);// >> 运算符重载friend istream &operator>>(istream &in,Father &f1);int get_age()const{return age;}void set_age(int age){this->age = age;}
protected:string name;
};Father &Father::operator=(const Father &other)
{age = other.age;*f = *(other.f);money = other.money;name = other.name;return *this;
}
ostream &operator<<(ostream &out,const Father &f1)
{out << "age = " << f1.age << "\t"<< "money = " << f1.name << "\t"<< "name = " << f1.name << "\t";return out;
}
istream &operator>>(istream &in,Father &f1)
{cout << "请输入age:";in >> f1.age;cout << "请输入money:";in >> f1.money;cout << "请输入f:";in >> *f1.f;cout << "请输入name:";in >> f1.name;return in;
}
Father Father::operator+(const Father &other)
{Father temp;temp.age = age+other.age;temp.money = money+other.money;temp.name = name+other.name;return temp;
}void Father::show_add()
{cout << "father_address:\t\t\t" << &age << endl;cout << "father::money_address:\t\t" << &money << endl;cout << "father::name_address:\t\t" << &name << endl;}class Son : public Father
{int a;int *s;
public:void show_Sadd();//无参构造Son():s(new int (0) ){}//有参构造Son(int age,double money,int f,string name,int a,int s):Father(age,money,f,name),a(a),s(new int (s)){}//拷贝构造  直接传子类的other对象调用父类的拷贝构造Son(const Son &other):Father(other),a(other.a),s(new int(*(other.s))){}~Son(){//delete f;delete s;}// = 运算符重载Son &operator=(const Son &other);// + 运算符重载Son operator+(const Son &other);// << 运算符重载friend ostream &operator<<(ostream &out ,const Son &s1);};
Son &Son::operator=(const Son &other)
{this->Father::operator=(other);*s = *(other.s);a = other.a;return  *this;
}ostream &operator<<(ostream &out ,const Son &s1)
{out << "age = " << s1.get_age() << "\t"<< "money = " << s1.money << "\t"<< "*f = " << *s1.f << "\t"<< "name = " << s1.name << "\t"<< "a = " << s1.a << "\t"<< "*s = " << *s1.s;return out;
}Son Son::operator+(const Son &other)
{Son temp;temp.Father::operator=(this->Father::operator+(other));delete s;s = new int (*this->s + *other.s);temp.a = a+other.a;return temp;
}void Son::show_Sadd()
{cout << "s = " << s << endl;cout << "*s = " << *s << endl;cout << "对象大小:" << endl;cout << "sizeof(Father) = " << sizeof(Father) << endl;cout << "sizeof(Son) = " << sizeof(Son) << endl;cout << "\n地址信息:" << endl;cout << "son_address:\t\t\t" << this << endl;show_add();cout << "son.a_address:\t\t\t" << &a << endl;cout << "\n地址偏移量:" << endl;cout << "money偏移:\t\t\t" << (char*)&money - (char*)this << endl;cout << "name偏移:\t\t\t" << (char*)&name - (char*)this << endl;cout << "a偏移:\t\t\t\t" << (char*)&a - (char*)this << endl;
}
int main()
{Son s1(18,999999,66,"张三",11,22);Son s2;s2 = s1;s1.show_Sadd();cout << s1 << endl;s2.show_Sadd();cout << s2 << endl;return 0;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com