C++: Compiler and Linker functionality

后端 未结 8 480
野趣味
野趣味 2020-12-10 08:39

I want to understand exactly which part of a program compiler looks at and which the linker looks at. So I wrote the following code:

#include          


        
8条回答
  •  庸人自扰
    2020-12-10 08:41

    I believe this is your question:

    Where I get confused is when compiler complained about DefinedIncorrectFunction. It didn't look for implementation of NonDefinedFunction but it went through the DefinedIncorrectFunction.

    The compiler tried to parse DefinedIncorrectFunction (because you provided a definition in this source file) and there was a syntax error (missing semicolon). On the other hand, the compiler never saw a definition for NonDefinedFunction because there simply was no code in this module. You might have provided a definition of NonDefinedFunction in another source file, but the compiler doesn't know that. The compiler only looks at one source file (and its included header files) at a time.

提交回复
热议问题