C++运算符重载,匿名对象,三连等

,目录

 1、加号运算符重载

1.1 通过自己写成员函数,实现两个对象相加属性后返回新的对象

1.2通过成员函数实现加法运算符重载

1.3通过全局函数实现加法运算符重载,运算符重载也可以发生函数重载

 1.4总结--对于内置的数据类型的表达式运算符是不可以改变的

2.左移运算符

2.1不会利用成员函数重载成员函数

2.2只能利用全局函数重载左移运算符

3.递增运算符重载

 3.1重载前置递增运算符

3.1.1成员函数重载前置递增运算符

 3.1.2利用全局函数重载前置递增运算符

3.2重载后置递增运算符

3.2.1利用成员函数重载后置递增运算符

3.2.2利用全局函数重载后置递增

4.赋值运算符重载

5.关系运算符重载

 5.1利用成员函数重载关系运算符

5.2利用全局函数重载关系运算符

6.函数调用运算符()(小括号)重载,匿名函数对象,匿名对象

 1、加号运算符重载

1.1 通过自己写成员函数,实现两个对象相加属性后返回新的对象

#include<iostream>
using namespace std;

class Person
{
public:
	int m_A;
	int m_B;
	Person PersonAddPerson(Person& p)
	{
		Person temp;
		temp.m_A = this->m_A + p.m_A;
		temp.m_B = this->m_B + p.m_B;
		return temp;    
	}
	
	/*第二种写法
	Person & PersonAddPerson(Person& p1, Person& p2)
	{
		this->m_A = p1.m_A + p2.m_A;
		this->m_B = p1.m_B + p2.m_B;
		return *this;
	}
	*/

};
void test01()
{
	Person p1;
	p1.m_A = 10;
	p1.m_B = 10;
	Person p2;
	p2.m_A = 10;
	p2.m_B = 10;
	Person p3 = p1.PersonAddPerson(p2);
	
	//Person p3;第二种写法的调用
	//p3.PersonAddPerson(p1, p2);

	cout << p3->m_A << " " << p3->m_B << endl;
}
int main()
{
	test01();
	system("pause");//按任意键继续
	return 0;
}

1.2通过成员函数实现加法运算符重载

#include<iostream>
using namespace std;

//加号运算符重载




class Person
{
public:
	int m_A;
	int m_B;
	//1、成员函数重载+号
	Person operator+(Person& p)//operator+编译器起的函数名
	{
		Person temp;
		temp.m_A = this->m_A + p.m_A;
		temp.m_B = this->m_B + p.m_B;
		return temp;    
	}
	

};


void test01()
{
	Person p1;
	p1.m_A = 10;
	p1.m_B = 10;
	Person p2;
	p2.m_A = 10;
	p2.m_B = 10;

	Person p3 = p2.operator+(p1);
	//Person p3 = p1 + p2;//成员函数重载本质调用Person p3=p2.operator+(p1)
	cout << "p3.m_A = "<<p3.m_A << " " <<"p3.m_B = "<< p3.m_B << endl;
}
int main()
{
	test01();
	system("pause");//按任意键继续
	return 0;
}

1.3通过全局函数实现加法运算符重载,运算符重载也可以发生函数重载

#include<iostream>
using namespace std;

//加号运算符重载




class Person
{
public:
	int m_A;
	int m_B;
	
};

//2、全局函数重载+号
Person operator+(Person& p1, Person& p2)
{
	Person temp;
	temp.m_A = p1.m_A+p2.m_A;
	temp.m_B = p1.m_B+p2.m_B;
	return temp;
}

//运算符重载 也可以发生函数重载
Person operator+(Person& p1, int num)
{
	Person temp;
	temp.m_A = p1.m_A +num;
	temp.m_B = p1.m_B + num;
	return temp;
}
void test01()
{
	Person p1;
	p1.m_A = 10;
	p1.m_B = 10;
	Person p2;
	p2.m_A = 10;
	p2.m_B = 10;

	//Person p3 = operator+(p1, p2);
	Person p3 = p1 + p2;//全局函数重载本质调用Person p3 = operator+(p1, p2);
	cout << p3.m_A << " " << p3.m_B << endl;
	Person p4 = p1 + 100;
	cout << p4.m_A << " " << p4.m_B << endl;
	//运算符重载 也可以发生函数重载

}
int main()
{
	test01();
	system("pause");//按任意键继续
	return 0;
}

 1.4总结--对于内置的数据类型的表达式运算符是不可以改变的

对于内置的数据类型的表达式运算符是不可以改变的,比如你把两个整型数据相加的,在函数里面写两数相减,这是不允许的

2.左移运算符

2.1不会利用成员函数重载成员函数

#include<iostream>
using namespace std;

//左移运算符
class Person
{
public:

	//利用成员函数重载 左移运算符
	//p.operator<<(cout) 简化版本p<<cout
	//所以不会利用成员函数重载<<运算符,因为无法实习cout在左侧
	//即cout<<
	void operator<<(cout)
	{
       //但你不知道返回什么就先写void
	}
	int m_A;
	int m_B;

};
void test01()
{
	Person p;
	p.m_A = 10;
	p.m_B = 10;
	cout << p.m_A  << endl;
}




int main()
{
	test01();
	system("pause");//按任意键继续
	return 0;
}

2.2只能利用全局函数重载左移运算符

#include<iostream>
using namespace std;

//左移运算符
class Person
{
public:

	int m_A;
	int m_B;

};


//只能利用全局函数重载左移运算符
void operator<<(ostream& cout, Person& p)//本质 operator<<(cout,p)简化为cout<<p
{
	//cout是输出流对象
	//cout只能有一个,要用引用的方式传递
	cout << "m_A = " << p.m_A << " " << "m_B = " << p.m_B;
}

void test01()
{
	Person p;
	p.m_A = 10;
	p.m_B = 10;
	cout <<p;
	//cout << p << endl;//报错
	// 链式调用
	//是因为cout << p本质 operator<<(cout,p),返回值为空,当然不能往后追加内容了
	//不能写endl
}


int main()
{
	test01();
	system("pause");//按任意键继续
	return 0;
}
=
#include<iostream>
using namespace std;

//左移运算符
class Person
{
	//全局函数做Person的好朋友,可以访问Person类的私有成员
	friend ostream& operator<<(ostream& cout, Person& p);
public:
	Person(int a, int b)
	{
		m_A = a;
		m_B = b;
	}

private:

	int m_A;
	int m_B;

};


//只能利用全局函数重载左移运算符
ostream& operator<<(ostream& cout, Person& p)//本质 operator<<(cout,p)简化为cout<<p
{
	//cout是输出流对象
	//cout只能有一个,要用引用的方式传递
    //因为属性私有,所以设为友元
	cout << "m_A = " << p.m_A << " " << "m_B = " << p.m_B;
	return cout;
}
/*
这样也对
ostream& operator<<(ostream& out, Person& p)//本质 operator<<(cout,p)简化为cout<<p
{
	
	out << "m_A = " << p.m_A << " " << "m_B = " << p.m_B;
	return out;
}
*/

void test01()
{
	Person p(10,10);
	//链式编程思想
	cout << p  << endl;
	//cout << p本质 operator<<(cout,p),返回cout
	//执行cout<<endl endl(在 << 右边)不符合右边的形参(person类)的要求
	//endl不是Person类 所以使用iostream中定义的 <<
	//此时的 << 只是最普通的 << ,而不是运算符重载后的 <<
	cout << p << " hello word" << endl;
}


int main()
{
	test01();
	system("pause");//按任意键继续
	return 0;
}

3.递增运算符重载

 自己写一个整型的数据,实现递增运算

 3.1重载前置递增运算符

3.1.1成员函数重载前置递增运算符

#include<iostream>
using namespace std;

//递增元素符重载

//自定义整型
class MyInteger
{
	friend ostream& operator<<(ostream& cout, MyInteger myint);
public:
	MyInteger()
	{
		m_Num = 0;
	}
	//重载前置++运算符
	//当不知道返回什么 就先写void
	MyInteger& operator++()
	{
		//先进性++运算
		m_Num++;
		//再将自身返回
		return *this;//返回自身
		/*
		返回引用是为了一直对一个数据进行递增操作
		因为
		int a=0;
		cout<<++(++a)<<endl;//输出2
		cout<<a<<endl;//输出2
		一直在对a这一个数进行操作

		如果返回值,会创建一个拷贝出来一个副本
		*/

	}
	//重载后置++运算符


private:
	int m_Num;
};

//重载<<(左移)运算符
ostream& operator<<(ostream& cout, MyInteger myint)
{
	cout << myint.m_Num;//因为私有,所以做友元
	return cout;
}
void test01()
{
	MyInteger myint;
	cout << myint << endl;
	cout << ++(++myint) << endl;
	cout <<myint << endl;
}


int main()
{
	test01();
	system("pause");//按任意键继续
	return 0;
}

 3.1.2利用全局函数重载前置递增运算符

#include<iostream>
using namespace std;

//递增元素符重载

//自定义整型
class MyInteger
{
	friend ostream& operator<<(ostream& cout, MyInteger &myint);
	friend MyInteger& operator++(MyInteger& myint);
public:
	MyInteger()
	{
		m_Num = 0;
	}
private:
	int m_Num;
};

//重载前置++运算符
MyInteger& operator++(MyInteger& myint )
{
	myint.m_Num++;
	return myint;
}


//重载<<(左移)运算符
ostream& operator<<(ostream& cout, MyInteger &myint)
{
	cout << myint.m_Num;//因为私有,所以做友元
	return cout;
}
void test01()
{
	MyInteger myint;
	cout << ++(++myint) << endl;
	cout << myint << endl;
}
int main()
{
	test01();
	system("pause");//按任意键继续
	return 0;
}


3.2重载后置递增运算符

3.2.1利用成员函数重载后置递增运算符

#include<iostream>
using namespace std;

//递增元素符重载

//自定义整型
class MyInteger
{
	friend ostream& operator<<(ostream& cout, MyInteger myint);
public:
	MyInteger()
	{
		m_Num = 0;
	}
	//重载前置++运算符
	MyInteger& operator++()
	{
		m_Num++;
		return *this;
	}
	//重载后置++运算符
	//同一个作用域下,函数名相同,发生了重载,
	// 函数返回值不可以作为重载条件
	//写个int作为占位参数,必须写int 写double float不好使
	//用于区分前置和后置
	//加了int之后,编译器就会认为这是后置的++运算符重载
	//但是前面讲过占位参数调用时必须填补呀,感觉是程序的规定
	//就是你写了int编译器自己就可以区分了
	MyInteger operator++(int)
	{
		/*
		//先返回结果
		return *this;
		//后 递增
		m_Num++;
		如果写return 那么后面的代码就不执行了
		*/
		//先记录结果
		MyInteger temp = *this;
		//后递增
		m_Num++;
		//最后将记录结果返回
		return temp;
		//如果是后置递增,要返回值
		//返回局部对象引用后面就是非法操作,因为,temp是局部变量
		//局部变量在当前函数执行完后就被释放掉了
	}
	
private:
	int m_Num;
};

//重载<<(左移)运算符
ostream& operator<<(ostream& cout, MyInteger myint)
{
	cout << myint.m_Num;//因为私有,所以做友元
	return cout;
}

void test02()
{
	MyInteger myint;
	cout << myint++ << endl;
	cout << myint << endl;

	/*
	int a = 0;
	cout << (a++)++ << endl;//报错
	cout << a << endl;
	因为在重载后置运算符时我们返回的是值
	所以(myint++)++是不会对同一个数据操作
	实际上我们看,系统自带的也不支持这种操作
	*/
}


int main()
{
	test02();
	system("pause");//按任意键继续
	return 0;
}

上面的代码我们注意到

 左移运算符,对象是以值传递的方式传入的。那我能不能写成引用呢?答案是可以的

#include<iostream>
using namespace std;

//递增元素符重载

//自定义整型
class MyInteger
{
	friend ostream& operator<<(ostream& cout, MyInteger &myint);
public:
	MyInteger()
	{
		m_Num = 0;
	}
	//重载前置++运算符
	MyInteger& operator++()
	{
		m_Num++;
		return *this;
	}
	//重载后置++运算符
	MyInteger operator++(int)
	{
		/*
		//先返回结果
		return *this;
		//后 递增
		m_Num++;
		如果写return 那么后面的代码就不执行了
		*/
		//先记录结果
		MyInteger temp = *this;
		//后递增
		m_Num++;
		//最后将记录结果返回
		return temp;
	}
private:
	int m_Num;
};

//重载<<(左移)运算符
ostream& operator<<(ostream& cout, MyInteger &myint)
{
	cout << myint.m_Num;//因为私有,所以做友元
	return cout;
}

void test02()
{
	MyInteger myint;
	MyInteger temp = myint++;
	cout << temp << endl;
	cout << myint << endl;
	//这个时候需要写个变量去接受myint++返回的对象
	//如果直接写cout << myint++ << endl;会报错
	//以值的方式返回对象,会调用拷贝构造函数,
	//复制出一个临时副本,感觉应该是这个副本没具体被接收
}


int main()
{
	test02();
	system("pause");//按任意键继续
	return 0;
}

 重载后置++运算符时,返回引用,此时需要用到new

#include<iostream>
using namespace std;

//递增元素符重载

//自定义整型
class MyInteger
{
	friend ostream& operator<<(ostream& cout, MyInteger &myint);
public:
	MyInteger()
	{
		m_Num = 0;
	}
	//重载前置++运算符
	MyInteger& operator++()
	{
		m_Num++;
		return *this;
	}
	//重载后置++运算符
	MyInteger& operator++(int)
	{
		//也可以直接 new 一个类,然后就可以返回引用了,占用内存还小
		
		//先记录结果
		MyInteger* temp = new MyInteger;
		*temp = *this;
		//后递增
		m_Num++;
		//最后将记录结果返回
		return *temp;
	}
	
private:
	int m_Num;
};

//重载<<(左移)运算符
ostream& operator<<(ostream& cout, MyInteger &myint)
{
	cout << myint.m_Num;//因为私有,所以做友元
	return cout;
}

void test02()
{
	MyInteger myint;
	cout << myint++ << endl;
	cout << myint << endl;
}


int main()
{
	test02();
	system("pause");//按任意键继续
	return 0;
}

3.2.2利用全局函数重载后置递增

#include<iostream>
using namespace std;

//递增元素符重载

//自定义整型
class MyInteger
{
	friend ostream& operator<<(ostream& cout, MyInteger myint);
	friend MyInteger& operator++(MyInteger& myint);
	friend MyInteger operator++(MyInteger& myint, int);
public:
	MyInteger()
	{
		m_Num = 0;
	}
private:
	int m_Num;
};

//重载前置++运算符
MyInteger& operator++(MyInteger& myint )
{
	myint.m_Num++;
	return myint;
}

//重载后置++运算符
MyInteger operator++(MyInteger& myint,int)
{
	cout << "后置" << endl;
	//先记录结果
	MyInteger temp = myint;
	//后递增
	myint.m_Num++;
	//最后将记录结果返回
	return temp;
}

//重载<<(左移)运算符
ostream& operator<<(ostream& cout, MyInteger myint)
{
	cout << myint.m_Num;//因为私有,所以做友元
	return cout;
}
void test02()
{
	MyInteger myint;
	cout << myint++ << endl;
	cout << myint << endl;
}
int main()
{
	test02();
	system("pause");//按任意键继续
	return 0;
}


4.赋值运算符重载

下面代码 会报错,原因如下面图片所述 

#include<iostream>
using namespace std;

//赋值运算符重载

class Person
{
public:
	Person(int age)
	{
		m_Age=new int(age);//将age数据开辟在堆区
	}
	~Person()
	{
		if (m_Age != NULL)
		{
			delete m_Age;
			m_Age = NULL;
		}
	}
	int* m_Age;//开辟 到堆区
};
void test01()
{
	Person p1(18);

	Person p2(20);

	p2 = p1;//赋值操作
	cout << "p1的年龄为 " << *p1.m_Age<<endl;
	cout << "p2的年龄为 " << *p2.m_Age << endl;
}
int main()
{
	test01();
	system("pause");//按任意键继续
	return 0;
}

 解决方法

 第一种,自己写个拷贝构造函数将p1赋值给p2

#include<iostream>
using namespace std;

//赋值运算符重载

class Person
{
public:
	Person(int age)
	{
		m_Age=new int(age);//将age数据开辟在堆区
	}
	Person(const Person &p)
	{
		m_Age = new int(*p.m_Age);
	}
	~Person()
	{
		if (m_Age != NULL)
		{
			delete m_Age;
			m_Age = NULL;
		}
	}
	int* m_Age;//开辟 到堆区
};
void test01()
{
	Person p1(18);

	Person p2(p1);

	//赋值操作
	cout << "p1的年龄为 " << *p1.m_Age<<endl;
	cout << "p2的年龄为 " << *p2.m_Age << endl;
}
int main()
{
	test01();
	system("pause");//按任意键继续
	return 0;
}

第二种,重载赋值运算符,必须用成员函数重载赋值运算符

#include<iostream>
using namespace std;

//赋值运算符重载

class Person
{
public:
	Person(int age)
	{
		m_Age=new int(age);//将age数据开辟在堆区
	}
	~Person()
	{
		if (m_Age != NULL)
		{
			delete m_Age;
			m_Age = NULL;
		}
	}

	//重载 赋值运算符
	Person& operator=(Person &p)
	{
		//编译器提共的是浅拷贝
		//m_Age = p.m_Age;

		//应该判断是否有属性在堆区, 如果有先释放干净, 然后在深拷贝
		//将p1的数据给到p2,但是p2已经有一块内存了
		if (m_Age != NULL)
		{
			delete m_Age;
			m_Age = NULL;
		}
		//深拷贝
		m_Age = new int(*p.m_Age);
		//返回对象本身
		return *this;
		//返回引用才是真正的自身
	}
	int* m_Age;//开辟 到堆区
};
void test01()
{
	Person p1(18);

	Person p2(20);

	Person p3(30);
    //p2 = p1;//本质上是p2.operator(p1)

	p3=p2 = p1;//赋值操作
	cout << "p1的年龄为 " << *p1.m_Age<<endl;
	cout << "p2的年龄为 " << *p2.m_Age << endl;
	cout << "p3的年龄为 " << *p3.m_Age << endl;
}
int main()
{
	test01();

	/*
	int a = 10,b=20,c=30;
	c = b = a;
	//将a的值赋值给b,此时b为10
	//再将b的值赋值给c,此时c也为10
	cout << "a = " << a << endl;//输出 10
	cout << "b = " << b << endl;//输出 10
	cout << "c = " << c << endl;//输出 10
	*/
	
	system("pause");//按任意键继续
	return 0;
}
#include<iostream>
using namespace std;

//赋值运算符重载

class Person
{
public:
	Person(int age)
	{
		m_Age = new int(age);//将age数据开辟在堆区
	}
	~Person()
	{
		if (m_Age != NULL)
		{
			delete m_Age;
			m_Age = NULL;
		}
	}

	//重载 赋值运算符
	Person& operator=( Person &p)
	{
		//编译器提共的是浅拷贝
		//m_Age = p.m_Age;

		//应该判断是否有属性在堆区, 如果有先释放干净, 然后在深拷贝
		//将p1的数据给到p2,但是p2已经有一块内存了
		if (m_Age != NULL)
		{
			delete m_Age;
			m_Age = NULL;
		}
		//深拷贝
		m_Age = new int(*p.m_Age);
		//返回对象本身
		return *this;
		//返回引用才是真正的自身
		
		//不返回void 是因为我们可能会采取a=b=c,如果b=c返回void就没法给a赋了
		//那为什么返回引用呢?
		//如果返回值,即返回类对象会调用拷贝构造函数
		//而我们没给,编译器默认给的是浅拷贝
		//那析构就会带来问题,堆区数据被重复释放
		//如果没有创建在堆区的数据是可以返回值的
		
		// 返回值时不能写a=b=c这种
		// 为什么呢?因为我们写的是(Person &p)
		//b=c时我们返回return *this,返回的是左值,不可以修改,是值
		// 而我们又传入的是引用,报错
		//不理解先看博客
		//https://blog.csdn.net/qq_37891604/article/details/128210998?spm=1001.2014.3001.5501
		//
		//所以想返回值还想实现a=b=c怎么办?
		//Person operator=(const Person & p)
		// 那就将引用改为常量引用
		
		
	}
	int* m_Age;//开辟 到堆区
};
void test01()
{
	Person p1(18);

	Person p2(20);

	Person p3(30);
	//p2 = p1;//本质上是p2.operator(p1)

	p3 = p2 = p1;//赋值操作
	cout << "p1的年龄为 " << *p1.m_Age << endl;
	cout << "p2的年龄为 " << *p2.m_Age << endl;
	cout << "p3的年龄为 " << *p3.m_Age << endl;
}
int main()
{
	test01();

	/*
	int a = 10,b=20,c=30;
	c = b = a;
	//将a的值赋值给b,此时b为10
	//再将b的值赋值给c,此时c也为10
	cout << "a = " << a << endl;//输出 10
	cout << "b = " << b << endl;//输出 10
	cout << "c = " << c << endl;//输出 10
	赋值采用的是右结合律,所以上述连锁赋值被解析为:
    x = (y = (z = 15)); //赋值连锁形式
    这里15先被赋值给z,然后其结果(更新后的z)再被赋值给y,
    然后其结果(更新后的y)再被赋值给x。
	*/

	system("pause");//按任意键继续
	return 0;
}

 

5.关系运算符重载

 

 5.1利用成员函数重载关系运算符

#include<iostream>
using namespace std;

//重载关系运算符
class Person
{
public:
	Person(string name, int age)
	{
		m_Name = name;
		m_Age = age;
	}

	//重载==
	bool operator==(Person &p)
	{
		if (this->m_Name == p.m_Name && this->m_Age == p.m_Age)
		{
			return true;
		}
		return false;
	}

	//重载!=
	bool operator!=(Person& p)
	{
		if (this->m_Name != p.m_Name || this->m_Age != p.m_Age)
		{
			return true;
		}
		return false;
	}
	string m_Name;
	int m_Age;
};
void test01()
{
	Person p1("Tom", 18);
	Person p2("Tom", 18);
	if (p1 == p2)//本质p1.operator==(p2)
	{
		cout << "p1和p2是相等的" << endl;
	}
	else
	{
		cout << "p1和p2是不相等的" << endl;
	}
	if (p1 != p2)//本质p1.operator==(p2)
	{
		cout << "p1和p2是不相等的" << endl;
	}
	else
	{
		cout << "p1和p2是相等的" << endl;
	}
}
int main()
{
	
	test01();
	system("pause");//按任意键继续
	return 0;
}

5.2利用全局函数重载关系运算符

#include<iostream>
using namespace std;

//重载关系运算符
class Person
{
public:
	Person(string name, int age)
	{
		m_Name = name;
		m_Age = age;
	}

	
	string m_Name;
	int m_Age;
};
//重载==
bool operator==(Person& p1,Person &p2)
{
	if (p1.m_Name == p2.m_Name && p1.m_Age == p2.m_Age)
	{
		return true;
	}
	return false;
}

//重载!=
bool operator!=(Person& p1, Person& p2)
{
	if (p1.m_Name !=p2.m_Name || p1.m_Age != p2.m_Age)
	{
		return true;
	}
	return false;
}
void test01()
{
	Person p1("Tom", 18);
	Person p2("Jerry", 18);
	if (p1 == p2)//本质operator==(p1,p2)
	{
		cout << "p1和p2是相等的" << endl;
	}
	else
	{
		cout << "p1和p2是不相等的" << endl;
	}
	if (p1 != p2)//本质p1.operator==(p2)
	{
		cout << "p1和p2是不相等的" << endl;
	}
	else
	{
		cout << "p1和p2是相等的" << endl;
	}
}
int main()
{
	
	test01();
	system("pause");//按任意键继续
	return 0;
}

6.函数调用运算符()(小括号)重载,匿名函数对象,匿名对象

#include<iostream>
using namespace std;

//函数调用运算符重载

//打印输出类
class MyPrint
{
public:

	//重载函数调用运算符
	void operator()(string test)
	{
		cout << test << endl;
	}
};
void MyPrint02(string test)
{
	cout << test << endl;
}
void test01()
{
	MyPrint myPrint;
	myPrint("hello word");//很像下面的函数调用
	//由于使用起来非常类似于函数调用,因此称为仿函数
	MyPrint02("xyq");//函数调用
}

//仿函数非常灵活,没有固定的写法

//加法类
class MyAdd
{
public:
	int operator()(int num1, int num2)
	{
		return num1 + num2;
	}
};
void test02()
{
	MyAdd myAdd;
	int ret=myAdd(10,10);
	cout << ret<< myAdd(10, 10) << endl;

	//匿名函数对象
	//因为重载了小括号称为匿名函数对象
	cout << MyAdd()(100, 100) << endl;
	// MyAdd()会创建出来一个匿名对象,通过类名加小括号会创建出来一个匿名对象
	//匿名函数对象有一个特点当前行执行完了立即被释放
	//匿名对象在构造函数分类及调用时讲过
}
int main()
{
	test01();
	test02();
	system("pause");//按任意键继续
	return 0;
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值