[ create a new paste ] login | about

Link: http://codepad.org/aezJOcj1    [ raw code | output | fork ]

C++, pasted on May 17:
#include <iostream>

struct A {
public:
	int id;
	bool copy;

	explicit A() : id(42) {
		std::cout << "CTor: " << id << std::endl;

		copy = false;
	}

	A(int val) : id(val) {
		std::cout << "CTor: " << id << std::endl;

		copy = false;
	}

	A(const A& a) {
		std::cout << "Copy CTor" << std::endl;

		copy = true;
		id = a.id * 2;
	}

	A(const A&& a) {
		std::cout << "Move" << std::endl;

		id = a.id;
		copy = false;
	}

	~A() {
		if (copy)
			std::cout << "Copy ";
		
		std::cout << "DTor: " << id << std::endl;
	}
};

void foo(A a) {
	std::cout << "foo says " << a.id << std::endl;
}

int main() {
	A a;
	foo(a);
	std::cout << "====" << std::endl;
	foo(A(23));
	std::cout << "end of main" << std::endl;
}


Output:
1
2
Line 27: error: expected ',' or '...' before '&&' token
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: