Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- class T {
- int i = 0;
- public:
- explicit T(int i): i(i) {}; // 기본 생성자
- T operator+ (const T& t) const {
- T t_(i + t.i);
- return t_;
- }
- T(T& t) { // 복사 생성자
- std::cout << "copy called" << std::endl;
- i = t.i;
- std::cout << "constructor ended" << std::endl;
- }
- T(T&& t) noexcept { // 이동 생성자
- std::cout << "move called" << std::endl;
- i = t.i;
- std::cout << "constructor ended" << std::endl;
- }
- ~T() { // 소멸자
- std::cout << "destroyed" << std::endl;
- }
- };
- int main() {
- T t1(10);
- T t2(20);
- std::cout << "(1) ============" << std::endl;
- T&& t3 = t1 + t2;
- std::cout << std::endl;
- std::cout << "(2) ============" << std::endl;
- T t3_1 = t1 + t2;
- std::cout << std::endl;
- std::cout << "(3) ============" << std::endl;
- const T& t4 = t1 + t2;
- std::cout << std::endl;
- std::cout << "(4) ============" << std::endl;
- T& t5 = t1;
- std::cout << std::endl;
- std::cout << "(5) ============" << std::endl;
- T t5_1 = t1;
- std::cout << std::endl;
- std::cout << "code fin\n" << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement