문제

In c++, is there any other way, besides header files, to use a function defined in file A.cpp, inside file B.cpp that would be considered good programming practice?

도움이 되었습니까?

해결책

With your restriction of "besides header files", the answer is: No.

The C++ compiler compiles each source file independently. If you intend to use a declaration that appears only once, it must appear in a header file.

(This does not consider things that wouldn't be considered good programming practice, such as including one .cpp file within another, or using -D compiler command line macros to define extern symbols in more than one source file.)

다른 팁

Lazy C++ can automate the generation of .h and .cpp files from a common .cpp-like source, so you don't have to repeat yourself by maintaining the header file yourself.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 softwareengineering.stackexchange
scroll top