I'm developing a C++ solution with Visual Studio 2015.
I have a cpp source file and header file hpp with this declaration.
Header:
#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
And Source code:
#include "FreeFunctions.h"
inline bool IsNullOrWhiteSpace(string str)
{
return (str.empty() || (str.find_first_not_of(' ') == string::npos));
}
I use this function in a class:
#include "ConvertToOwnFormat.h"
#include "FreeFunctions.h"
ConvertToOwnFormat::ConvertToOwnFormat()
{
}
ConvertToOwnFormat::~ConvertToOwnFormat()
{
}
vector<Entry> ConvertToOwnFormat::ReadCatalogue(string path)
{
if (!IsNullOrWhiteSpace(path)
{
[ ... ]
}
}
And I get the following error in ConvertToOwnFormat::ReadCatalogue
:
Error LNK2019 external symbol "bool __cdecl IsNullOrWhiteSpace(class std::basic_string,class std::allocator >)" (?IsNullOrWhiteSpace@@YA_NV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) unresolved referenced by the function "public: class std::vector > __cdecl ConvertToOwnFormat::ReadCatalogue(class std::basic_string,class std::allocator >)" (?ReadCatalogue@ConvertToOwnFormat@@QEAA?AV?$vector@VEntry@@V?$allocator@VEntry@@@std@@@std@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@3@@Z) MyProjectLib D:\Fuentes\Repos\MyProject\MyProjectLibConsoleTest\ConsoleMyProjectLib\Lib.lib(ConvertToOwnFormat.obj) 1
MyLib__FREEFUNCTIONS__INCLUDE__
) and names that begin with an underscore followed by a capital letter are reserved to the implementation. Don't use them. – Pete Beckerusing namespace
inside a header is discouraged (stackoverflow.com/questions/5849457/…) – Garf365