我有这个函数,它仅在任何地方声明而不定义。但该程序在 C 中仍然可以正常工作,但在 C++ 中却不行。这怎么可能。
void pzKasittelija(char *lid, char *lid2); // this function is only declared not defined anywhere
PS:我检查了所有库和头文件,该函数未定义!!!
这是我使用 C++ 时收到的错误消息
Error 2 error C2440: '=' : cannot convert from 'void (__cdecl *)(char *,char *)' to 'void (__cdecl *)(...)'
请查看这些链接。这些是问题所在的文件。
https://drive.google.com/file/d/0B2hZqiBoBiNEcVFUTFJyZUZvY1U/edit?usp=sharing
https://drive.google.com/file/d/0B2hZqiBoBiNEZWl6VzR4bzFHWm8/edit?usp=sharing
最佳答案
因为这只是一个function prototype它只是通知编译器代码中将使用这样的函数。通过使用函数原型(prototype),您可以在调用函数的代码生成后定义函数。
当您包含 header 时,您就在该 .h
文件中包含了多个函数的原型(prototype),并且编译器不会期望您调用所有函数
关于c++ - 函数仅声明,但仍然有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21279999/