Can I write C++ code without headers (repetitive function declarations)?

前端 未结 24 824
半阙折子戏
半阙折子戏 2020-11-28 07:55

Is there any way to not have to write function declarations twice (headers) and still retain the same scalability in compiling, clarity in debugging, and flexibility in desi

24条回答
  •  感情败类
    2020-11-28 08:25

    You have to write function declaration twice, actually (once in header file, once in implementation file). The definition (AKA implementation) of the function will be written once, in the implementation file.

    You can write all the code in header files (it is actually a very used practice in generic programming in C++), but this implies that every C/CPP file including that header will imply recompilation of the implementation from those header files.

    If you are thinking to a system similar to C# or Java, it is not possible in C++.

提交回复
热议问题