类的默认构造函数,直接初始化,拷贝构造函数,赋值运算符的执行次数判断
来源:互联网 发布:java bigdecimal取整 编辑:程序博客网 时间:2024/06/03 13:05
类的默认构造函数,直接初始化,拷贝构造函数,赋值运算符的执行次数判断
#include<iostream>
#include<algorithm>
using namespace std;
class animal
{
public:
int a;
animal()
{
a = 0;
cout << "默认"<<endl;
}
animal(int x)
{
a = x;
cout << "直接初始化" << endl;
}
animal(const animal& x)
{
a = x.a;
cout << "拷贝" << endl;
}
animal& operator=(const animal& x)
{
cout << "=" << endl;
return *this;
}
animal& tesA(const animal& x)
{
return *this;
}
animal test2(const animal& x)
{
return *this;
}
};
int main()
{
animal A;
animal a2;
cout <<"事例1:";
a2 = A.tesA(A);
cout << "事例2:";
animal a3 = A.tesA(A);
cout << "事例3:" ;
a2 = A.test2(A);
cout << "事例4:" ;
animal a4 = a2.tesA(a2);
system("pause");
return 0;
}
#include<algorithm>
using namespace std;
class animal
{
public:
int a;
animal()
{
a = 0;
cout << "默认"<<endl;
}
animal(int x)
{
a = x;
cout << "直接初始化" << endl;
}
animal(const animal& x)
{
a = x.a;
cout << "拷贝" << endl;
}
animal& operator=(const animal& x)
{
cout << "=" << endl;
return *this;
}
animal& tesA(const animal& x)
{
return *this;
}
animal test2(const animal& x)
{
return *this;
}
};
int main()
{
animal A;
animal a2;
cout <<"事例1:";
a2 = A.tesA(A);
cout << "事例2:";
animal a3 = A.tesA(A);
cout << "事例3:" ;
a2 = A.test2(A);
cout << "事例4:" ;
animal a4 = a2.tesA(a2);
system("pause");
return 0;
}
阅读全文
0 0
- 类的默认构造函数,直接初始化,拷贝构造函数,赋值运算符的执行次数判断
- 默认构造函数,拷贝构造函数,拷贝赋值运算符
- 类的赋值运算符重载和拷贝构造函数
- 类的构造函数、拷贝构造函数、赋值运算符和析构函数
- String类的构造函数、析构函数、拷贝构造函数、赋值运算符重载
- 拷贝构造函数和赋值运算符的重载的调用次数问题
- 类的默认构造函数,赋值构造函数,拷贝构造函数
- 实现字符串类String的设计,实现赋值运算符重载函数,默认、一般、拷贝构造函数,析构函数
- 浅析类的 默认构造函数, 拷贝构造函数, 赋值拷贝函数“=”
- 拷贝构造函数与赋值运算符的重载函数
- 含有指针成员的类的构造函数、拷贝构造函数、赋值运算符
- 默认拷贝构造函数,默认赋值函数的考察
- c++中类的默认四个成员函数介绍(构造函数+拷贝构造+析构函数+赋值运算符重载函数)
- 看来,C++有默认的拷贝构造函数和赋值运算符=!
- 拷贝构造函数,类的赋值运算符重载,深拷贝与浅拷贝
- 重载赋值运算符与拷贝构造函数的区别
- 拷贝构造函数与赋值运算符重载的区别
- 拷贝构造函数与赋值运算符的区别
- 关于retrofit 传值传null的处理(同样适用于okhttp)
- win7自定义共享文件夹名称
- 机器学习相关定义(更新完监督学习)
- MVVM之DataBinding入门
- 13:反向输出一个三位数
- 类的默认构造函数,直接初始化,拷贝构造函数,赋值运算符的执行次数判断
- 分别用Java、Scala、spark-shell开发wordcount程序及测试代码
- 去掉<li>默认的标点
- Hadoop入门之自定义groupingcomparator和outputformat的使用
- can't read property 'style' of undefined(DataTable)
- Java简介以及环境搭建
- 运算符
- 记博客园的第一篇博客
- 链表