我昨天问了同样的问题,答案不适用.
如果我进入类标题,右键单击该函数并单击"转到定义",这使我在我的其他.CPP文件中使用了我的函数.它看到它,可以链接到它,但我仍然得到错误,表明我看不到它.
有人有什么建议吗?我会尝试任何事情.
这是错误.
zdll.lib(d000050.o):警告LNK4078:
'.text'
找到具有不同属性的多个部分(E0300020)WLD.obj:错误LNK2019:
"public: void __thiscall WLD::fragment_03(unsigned char *,int)" (?fragment_03@WLD@@QAEXPAEH@Z)
函数中引用的未解析的外部符号"public: bool __thiscall WLD::init(unsigned char *)" (?init@WLD@@QAE_NPAE@Z)
编辑:另外,我正在使用MSVC++.我应该尝试创建新解决方案并导入文件吗?可能会有所帮助,因为我觉得我没有选择......
编辑:这是代码:
#include "WLD.h"
inline void WLD::fragment_03(uchar* location, int frag_num)
{
// Read the struct into memory and create a temporary pointer
struct_frag03 temp03;
memcpy(&temp03, location, sizeof(struct_frag03));
uchar* temp_p = location;
// Advance the pointer to the encoded bytes (filename)
temp_p += sizeof(long) + sizeof(short);
// Grab the encoded filename and decode it
uchar* f_filename = new uchar [sizeof(temp03.nameLen + 1)];
memcpy(f_filename, temp_p, temp03.nameLen + 1);
decode(f_filename, temp03.nameLen);
// Add the details about this bitmap to the array
bmp_array[current_bmp].filename = f_filename;
bmp_array[current_bmp].nameLength = temp03.nameLen;
bmp_array[current_bmp].reference03 = frag_num;
// 0x03 Debug
//errorLog.OutputSuccess("0x03 Filename: %s", bmp_array[current_bmp].filename);
//errorLog.OutputSuccess("0x03 Name length: %i",bmp_array[current_bmp].nameLength);
//errorLog.OutputSuccess("0x03 Reference: %i", bmp_array[current_bmp].reference03);
// Add the bitmap to the count
current_bmp++;
}
Run Code Online (Sandbox Code Playgroud)
这里是WLD类中调用代码的地方:
case 0x03:
fragment_03(wld + file_pos + sizeof(struct_wld_basic_frag), i);
break;
Run Code Online (Sandbox Code Playgroud)
这是头文件声明:in(WLD.h):
public:
inline void fragment_03(uchar* location, int frag_num);
Run Code Online (Sandbox Code Playgroud)
inline
意味着该函数有效地具有内部链接(即,它必须存在于使用它的翻译单元内).将函数的定义移动到标题中,或者删除inline
.
(inline
对于现代编译器而言,实际上意味着"使用内部链接" - 编译器将内联它自己有意义的内容,并且它们通常比人类做出更好的决策)
编辑:从技术上讲,标准使用的语言说内联函数有外部链接; 但是,它也在An inline function shall be defined in every translation unit in which it is used.
标准的第3.2节第3段和There can be more than one definition of a ... inline function
with external linkage (7.1.2) ... Given such an entity named D defined in more than one translation unit ... each definition of D shall consist of the same sequence of tokens
第5 段中说过.因此从技术上讲,你所声明的内联名称可以从给定的翻译单元外部访问,这样做会导致C++中出现未定义的行为.