简体   繁体   English

在头文件中定义独立功能-C ++

[英]Defining standalone functions inside a header file - C++

When implementing a standalone function inside a header file, it gives an error "Error 4 fatal error LNK1169: one or more multiply defined symbols found" whereas standalone template functions and member functions of a class work fine when implemented inside a header file. 在头文件中实现独立功能时,会出现错误“错误4致命错误LNK1169:找到一个或多个乘以定义的符号”,而在头文件中实现时,独立模板函数和类的成员函数可以正常工作。

Is the normal standalone function needed to be defined as an inline function? 是否需要将普通的独立功能定义为内联功能? can anybody give me a clear explanation why? 有人可以给我清楚的解释原因吗?

Every time you include it - it gets redefined into that object file 每次包含它-它都会重新定义到该目标文件中

an inline function allows this because it isn't a linker object 内联函数允许这样做,因为它不是链接器对象

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

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