其他分享
首页 > 其他分享> > 记一次VS下LINK1169的错误

记一次VS下LINK1169的错误

作者:互联网

fatal error LNK1169: 找到一个或多个多重定义的符号

废话不多说,这也太坑了(花了半个小时找错误),不得不吐槽一下,当你的工程过于大了的时候,一定要把代码写规范,要不然哪里出现LINK错误真的要命。
这个错误在于我昨天在一个Event.h中写了一个全局的重载函数,如下

// 上面是一些class Event
std::ostream& operator<< (std::ostream& os, const Event& event)
{
	return os << event.ToString();
}

然后今天在写Window时引用了Event.h,发现总是会报这个1169这个链接错误,最后反复查找,终于把这个细微的点找到,改过后也build成功了。
解决方法就是在函数声明前加上inline,只要是.h文件中的全局函数写的时候都加上inline,不然当你inclue这个头文件时候就会造成编译器认为重复定义。这种错误情况还是比较少见(对我)的

// 上面是一些class Event
inline std::ostream& operator<< (std::ostream& os, const Event& event)
{
	return os << event.ToString();
}

标签:错误,operator,class,LINK1169,VS,ostream,inline,Event
来源: https://www.cnblogs.com/codemeta-2020/p/12859563.html