首页 > 其他分享 >LNK2005:继承std::string出现的问题

LNK2005:继承std::string出现的问题

时间:2022-11-17 10:35:20浏览次数:68  
标签:std __ string LNK2005 basic allocator

今天调整合并项目代码时候编译链接时出现问题:
error LNK2005: "public: __cdecl std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" (??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@XZ) 已经在 ModelTree.cpp.obj 中定义
error LNK2005: "public: unsigned __int64 __cdecl std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::max_size(void)const " (?max_size@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBA_KXZ) 已经在 ModelTree.cpp.obj 中定义

很是烦人,这类问题很难着手排查。只能百度搜索是否存在类似的问题。
找到一篇文章 https://blog.csdn.net/gongxun1994/article/details/83831219, 大体指出问题是由继承了STL中std::string导致的。
突然想到自己在底层库构建字符串类时候,写了个String的类模板,其中特例化了一个继承std::string的类。
将其注释掉之后,项目代码编译链接就没问题了。

标签:std,__,string,LNK2005,basic,allocator
From: https://www.cnblogs.com/zyq0923/p/16898566.html

相关文章