${x}tor

#include <iostream>
#include <random>
using namespace std;

class Foo {
public:
	Foo();
	~Foo();
	Foo(const Foo&);
	Foo & operator=(const Foo&);
};

Foo::Foo() {
	cout << "Foo ctor" << endl;
}

Foo::~Foo() {
	cout << "Foo dtor" << endl;
}

Foo::Foo(const Foo& t) {
	cout << "Foo copy ctor" << endl;
}

Foo& Foo::operator=(const Foo& t) {
	cout << "Foo asign op" << endl;
	return const_cast<Foo&>(t);
}

const Foo ft(Foo t) {
	return t;
}

void main() {
	const Foo f;	//Foo ctor
	Foo F;			//Foo ctor

	Foo r = ft(f);	//Foo copy ctor
					//Foo copy ctor
					//Foo dtor

	Foo g(f);		//Foo copy ctor
	Foo h = f;		//Foo copy ctor

	F = f;			//Foo asign op

	getchar();
}

posted @ 2020-11-16 09:31  fndefbwefsowpvqfx  阅读(67)  评论(0编辑  收藏  举报