In which file do we put non-member function in C++?

前端 未结 3 780
广开言路
广开言路 2021-01-28 15:49

What is the normal practice when it comes to non-member function in C++? Do we put them in main.cpp or header file or class implementation file, or do we make a separate .cpp fi

3条回答
  •  半阙折子戏
    2021-01-28 16:19

    Your class should have its own .cpp file. Non-member functions should go in other files (all together or grouped according to similarity). That's the convention here in North America, but conventions differ. Prototype just needs go into header file so you can include it wherever you use it.

提交回复
热议问题