简体   繁体   English

c++ 类和 .cpp 文件的单独文件,函数不是类的一部分

[英]c++ seperate files for class and .cpp file, Functions not part of class

Please just answer my simple question I am making separate file for classes .h file and separate for functions and one main.cpp file请回答我的简单问题,我正在为类 .h 文件制作单独的文件,并为函数和一个 main.cpp 文件制作单独的文件

Should I also put functions which are not part of the my class in separate cpp file??我还应该将不属于我的类的函数放在单独的 cpp 文件中吗? Actually some of my functions of class are also using other function not included in the class function.实际上,我的一些类函数也使用了类函数中未包含的其他函数。 So should I put all the functions including and not including in separate cpp file?那么我是否应该将包括和不包括在内的所有功能放在单独的 cpp 文件中?

Should I also put functions which are not part of the my class in separate cpp file??我还应该将不属于我的类的函数放在单独的 cpp 文件中吗?

if those functions are not strictly used only by your class then yes, ie.如果这些功能不是严格仅由您的班级使用,那么是的,即。 if they can be used in different projects, then it makes sense to put them in separate .cpp file.如果它们可以在不同的项目中使用,那么将它们放在单独的 .cpp 文件中是有意义的。

Actually some of my functions of class are also using other function not included in the class function.实际上,我的一些类函数也使用了类函数中未包含的其他函数。 So should I put all the functions including and not including in separate cpp file?????那么我应该把包括和不包括在内的所有功能放在单独的 cpp 文件中吗???????

hard to understand, but as above if those functions are only for your class use, then put them in .cpp file that contains implementation for your class methods.难以理解,但如上所述,如果这些函数仅供您的类使用,则将它们放在包含类方法实现的 .cpp 文件中。

Actually if you put some declarations in header file ah then you also put their definitions into a.cpp .实际上,如果您在头文件ah放入一些声明,那么您也将它们的定义放入a.cpp This is not a strict rule, you can put declarations in 'ah' and 'bh' while put all the definitions in c.cpp , but then its hard to find where which function is declared.这不是一个严格的规则,您可以将声明放在 'ah' 和 'bh' 中,而将所有定义放在c.cpp ,但是很难找到声明哪个函数的位置。 If you know that declaration is in ah then you simply look for definition in a.cpp .如果您知道声明在ah那么您只需在a.cpp查找定义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM