内联函数的链接器未解析外部符号 我正在用Visual Studio 2015开发一个C++解决方案。

内联函数的链接器未解析外部符号 我正在用Visual Studio 2015开发一个C++解决方案。,c++,C++,我有一个带有此声明的cpp源文件和头文件hpp 标题: #ifndef MyLib__FREEFUNCTIONS__INCLUDE__ #define MyLib__FREEFUNCTIONS__INCLUDE__ #include <iostream> #include <vector> #include <string> #include <sstream> using namespace std; // Check if 'str' i

我有一个带有此声明的cpp源文件和头文件hpp

标题:

#ifndef MyLib__FREEFUNCTIONS__INCLUDE__
#define MyLib__FREEFUNCTIONS__INCLUDE__

#include <iostream>
#include <vector>
#include <string>
#include <sstream>

using namespace std;

// Check if 'str' is null, empty or consists only of white-space characters. 
inline bool IsNullOrWhiteSpace(string str);

// More functions
[ ... ]

#endif
我在类中使用此函数:

#include "ConvertToOwnFormat.h"
#include "FreeFunctions.h"

ConvertToOwnFormat::ConvertToOwnFormat()
{
}


ConvertToOwnFormat::~ConvertToOwnFormat()
{
}

vector<Entry> ConvertToOwnFormat::ReadCatalogue(string path)
{
    if (!IsNullOrWhiteSpace(path)
    {
        [ ... ]
    }
}
#包括“ConvertToOwnFormat.h”
#包括“FreeFunctions.h”
ConvertToOwnFormat::ConvertToOwnFormat()
{
}
ConvertToOwnFormat::~ConvertToOwnFormat()
{
}
矢量ConvertToOwnFormat::ReadCatalog(字符串路径)
{
如果(!IsNullOrWhiteSpace(路径)
{
[ ... ]
}
}
我在
ConvertToOwnFormat::readcatalog
中得到以下错误:

错误LNK2019外部符号“bool\uu cdecl IsNullOrWhiteSpace(类 std::基本_字符串,类 std::分配器>)” (?IsNullOrWhiteSpace@@YA_NV?$basic)_string@DU?$char_traits@D@性病病毒$allocator@D@2@@@std@@@Z) 函数“public:class std::vector>\uu cdecl”引用的未解析 ConvertToOwnFormat::ReadCatalog(类std::基本字符串,类std::分配器>) (?ReadCatalogue@ConvertToOwnFormat@@QEAA?AV$vector@VEntry@@V$allocator@VEntry@@@std@@@std@@V?$basic_string@DU?$char_traits@D@性病病毒$allocator@D@2@@3@@Z)MyProjectLib D:\Fuentes\Repos\MyProject\MyProjectLibConsoleTest\ConsoleMyProjectLib\Lib.Lib(ConvertToOwnFormat.obj)1


您必须将方法声明放在头中。
inline
告诉编译器它应该用函数的核心替换函数的调用。因此,对于使用它的每个编译单元,它在编译时都需要它

#ifndef MyLib__FREEFUNCTIONS__INCLUDE__
#define MyLib__FREEFUNCTIONS__INCLUDE__

#include <iostream>
#include <vector>
#include <string>
#include <sstream>

// Check if 'str' is null, empty or consists only of white-space characters. 
inline bool IsNullOrWhiteSpace(std::string str)
{
    return (str.empty() || (str.find_first_not_of(' ') == std::string::npos));
}

// Others functions, prototype, ...

#endif
\ifndef MyLib\uu free函数包括__
#定义MyLib\uuu free函数\uuu包括__
#包括
#包括
#包括
#包括
//检查“str”是否为null、空或仅包含空格字符。
内联bool IsNullOrWhiteSpace(std::string str)
{
返回(str.empty()||(str.find_first_not_of(“”)=std::string::npos));
}
//其他功能、原型。。。
#恩迪夫
或者删除源文件和头文件中的内联
inline



这完全不符合主题,但决不要将
使用名称空间
放在头中:头应该提供一些东西,但不应该强加类似名称空间的东西。另请参见您必须将方法声明放在头中。
内联
告诉编译器,它应该用函数的核心替换函数的调用。因此,对于使用它的每个编译单元,它在编译时都需要它

#ifndef MyLib__FREEFUNCTIONS__INCLUDE__
#define MyLib__FREEFUNCTIONS__INCLUDE__

#include <iostream>
#include <vector>
#include <string>
#include <sstream>

// Check if 'str' is null, empty or consists only of white-space characters. 
inline bool IsNullOrWhiteSpace(std::string str)
{
    return (str.empty() || (str.find_first_not_of(' ') == std::string::npos));
}

// Others functions, prototype, ...

#endif
\ifndef MyLib\uu free函数包括__
#定义MyLib\uuu free函数\uuu包括__
#包括
#包括
#包括
#包括
//检查“str”是否为null、空或仅包含空格字符。
内联bool IsNullOrWhiteSpace(std::string str)
{
返回(str.empty()||(str.find_first_not_of(“”)=std::string::npos));
}
//其他功能、原型。。。
#恩迪夫
或者删除源文件和头文件中的内联
inline



这完全不符合主题,但决不要将
使用名称空间
放在头中:头应该提供一些东西,但不应该强加名称空间之类的东西。另请参见

我可能错了,但我相信内联通常用于头中的方法声明,而不是cpp文件。您尝试过吗?是的,我尝试过,它是正确的链接。谢谢。这不是问题所在,但是包含两个连续下划线(
MyLib\uuu freeffunctions\uu\uu INCLUDE\uuu
)的名称以及以下划线开头并后跟大写字母的名称将保留给实现。不要使用它们。这不是问题所在,但不建议在头中使用名称空间
()非常感谢您的评论。我正在学习,非常感谢他们。我可能错了,但我认为内联通常用于在标题中声明方法,而不是在cpp文件中。您尝试过这个吗?是的,我尝试过,它链接了。谢谢。这不是问题,而是包含两个连续下划线的名称(
MyLib\uuuu freeffunctions\uuuu INCLUDE\uuu
)和以下划线开头并后跟大写字母的名称保留给实现。不要使用它们。这也不是问题所在,但不建议在标题中使用名称空间
非常感谢您的评论。我正在学习,非常感谢。