这个问题困扰我有一段时间了。我有一个命名空间,在这个命名空间里我想声明C风格的函数。所以我做了我认为正确的事情:
namespace test
{
std::deque<unsigned> CSV_TO_DEQUE(const char* data);
std::deque<unsigned> ZLIB64_TO_DEQUE(const char* data, int width, int height);
std::string BASE64_DECODE(std::string const& encoded_string);
}
然后是实现文件:
#include "theheaderfile.hpp"
using namespace test;
std::deque<unsigned> CSV_TO_DEQUE(const char* data)
{
...
}
std::deque<unsigned> ZLIB64_TO_DEQUE(const char* data, int width, int height)
{
...
}
std::string BASE64_DECODE(std::string const& encoded_string)
{
...
}
然而,当我尝试调用这些函数时,出现了未定义引用错误。文件已经被链接,所以我不确定为什么引用是未定义的。
我还想补充一点,如果我将这些函数从test
命名空间中移除,保留在全局命名空间中,它们可以顺利运行。
我希望避免在头文件中定义这些函数,这是否可行?
std::deque<unsigned> test::CSV_TO_DEQUE(const char* data){/...}
来实现。 - BoBTFish