这已经困扰我一段时间了。我有一个命名空间,在该命名空间中我想声明 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
命名空间并将它们保留在全局命名空间中,它们可以顺利工作。
我想避免在标头中定义函数。这可能吗?
using namespace
只会导入名称空间以供使用 - 它不会让您在该名称空间中定义函数。
您仍然需要在测试命名空间内定义函数:
namespace test {
// your functions
};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)