3
当试图在Visual C++(2008 express)中内联函数时,我在仔细检查代码后发现链接错误,我发现的是函数I am试图内联抛出一个异常......如果我删除异常抛出,链接错误消失,有人可以解释为什么它是这种情况?尝试内联函数时在Visual C++中链接错误
int com_ximpleware::FastIntBuffer::intAt(int index){
if (index < 0 || index > size - 1) {
throw InvalidArgumentException("invalid index range in FastIntBuffer's intAt()");
}
return ((int *) al->get(index>>exp))[index & r];
}
如下所示的exaxt错误:
intHash.obj : error LNK2019: unresolved external symbol "public: int __thiscall com_ximpleware::FastIntBuffer::intAt(int)" ([email protected]@[email protected]@[email protected]) referenced in function [email protected]@[email protected]@[email protected]$0
1>C:\new_cvs\cpp_test1\Debug\cpp_test1.exe : fatal error LNK1120: 1 unresolved externals
一两件事,这个函数被调用别的正常,没有被列入该函数的调用部分。
当你将它嵌入时,是否将它移动到头文件中? – 2010-03-30 02:58:20
我把定义(即实现)在标题中,并没有问题...我必须将其移动到标题以内联它吗?我以为我可以声明它是一个内联函数,不是吗? – 2010-03-30 03:21:44
无论它在哪里调用,它都必须是可见的,所以通常它必须位于头文件中。 – Darryl 2010-03-30 03:33:48