托管 c++代码找不到函数实现
我有 3 个文件:
- 主“.h”文件 - 包含简单 WinForm(托管 C++)的实现
- Fold/file.h
- Fold/file.cpp
(file.h 和 file.cpp 不代表一个类)
我有一个函数“func()”,其声明位于fold/file.h,其实现位于fold/file.cpp。
main.h 中包含“fold/file.h”
当我从 main.h 调用 func() 时,我收到以下错误:“未解析的令牌”和“未解析的外部错误”。当我将“func()”的实现放入fold/file.h 时,没有错误。
问题是什么?
谢谢!
I have 3 files:
- main ".h" file - contains implementation of a simple WinForm (managed c++)
- fold/file.h
- fold/file.cpp
(file.h and file.cpp are not represent a class)
I have a function "func()" which its declaration is in fold/file.h, and its implementation is in fold/file.cpp.
There is include "fold/file.h" in main.h
When I call func() from main.h I get errors of: "Unresolved token" and "Unresolved external error". when I put the implementation of "func()" in fold/file.h there is no error.
What is the problem?
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在编译所有源文件吗?我怀疑您不是,因为当您将定义引入头文件并将其包含在主源文件中时,预处理器实际上将其复制到主源文件中。因此,在编译和链接主翻译单元时,编译器和链接器可以分别看到声明和定义。
Are you compiling all the source files ? I suspect you are not because when you bring the definitions to the header file and include it in the main source file, pre-processor actually copies it to the main source file. So, while compiling and linking the main translation unit, compiler and linker can see both the declarations and the definitions respectively.