view the default functions generated by a compiler?

后端 未结 5 1812
滥情空心
滥情空心 2020-12-28 22:17

Is there any way to view the default functions ( e.g., default copy constructor, default assignment operator ) generated by a compiler such as VC++2008 for a class which doe

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-28 22:47

    You can trace into the code with the debugger to see what is going on. For example:

    #include 
    
    struct A {
        int a[100];
        char c;
        std::string s;
    };
    
    int main() {
        A a;
        A b(a);
    }
    

    Set a breakpoint at the construction of 'b' by the copy constructor. The assembler output at that point in the VC++6 debugger is:

    12:       A b(a);
    00401195   lea         eax,[ebp-1B0h]
    0040119B   push        eax
    0040119C   lea         ecx,[ebp-354h]
    004011A2   call        @ILT+140(A::A) (00401091) 
    

    The last is the copy constructor call. You can trace into that too if you want more details.

    However, if your question is "how can I see the C++ code for the copy constructor et al", the answer is you can't, because there isn't any - the compiler generates assembler or machine code (depending on your compiler) for them, not C++ code.

提交回复
热议问题