C++함수 반환 값 을 대상 으로 할 때 구조 분석 함수 의 실행 디 테 일

다음 코드 보기:

#include<iostream>
class TestConstructor
{
public:
    TestConstructor()
    {
        std::cout<<"TestConstructor()"<<std::endl;
    }
    ~TestConstructor()
    {
        std::cout<<"~TestConstructor()"<<std::endl;
    }
    TestConstructor(const TestConstructor& testObj)
    {
        std::cout<<"TestConstructor(const TestConstructor&)"<<std::endl;
    }
    TestConstructor& operator = (const TestConstructor& testObj)
    {
        std::cout<<"TestConstructor& operator = (const TestConstructor& testObj)"<<std::endl;
        return *this;
    }
};
TestConstructor testFunc()
{
    TestConstructor testInFunc;  //3、 TestConstructor() testInFunc
    return testInFunc;           //4、 TestConstructor(const TestConstructor&)
                                 //5、 , testInFunc
}
int main()
{
    TestConstructor test;  //1、 TestConstructor() test
    test = testFunc();     //2、 testFunc()    //6、 test  //7、 ,
    return 0;              //8、 , test
}
출력 보기:

주석 이 있 고 출력 이 있 습 니 다.세부 사항 을 한눈 에 알 수 있 겠 지
 

좋은 웹페이지 즐겨찾기