我有一个公开的模板类,我在其中添加了一个方法。这个类在命名空间 A 中。现在,我在另一个命名空间(比如 B)中调用这个方法。最初,编译器给我的链接器错误是针对此特定方法的“未解析的外部符号”。
但是,如果我在同一个命名空间(即 A)内调用此方法,它会很好地链接。之后,它在命名空间 B 中也能很好地链接。
为什么会这样?
这与我的类的创建模板对象有关吗?
阿图尔
这是代码片段......
namespace sss
{
namespace AAA
{
template <<typename T, typename TAlloc = Allocator< T > >
class DLL_EXPORT A
{
public:
// Some other functions that are working fine ...
bool fooA() const;
{
return Size()>0;
}
};
}
}
//I get a linker error when I call it in another namespace (say B)...
//I am accessing this method in public method of some other class in namespace B
// Including the header for class A ...
#include A.h
namespace QQQ
{
namespace B
{
class B
{
private:
AAA::A obj; // Object of class A ...
public:
// SOme methods
// Method that calls fooA ...
GetResult()
{
fooA // This causes causes linker error when i call it here,
// but, it works when i call it in namespace AAA,
// and then it, it works here as well
}
};
当我从命名空间 B 中调用此方法时,它给出了未解析的外部符号,但是,当我从命名空间 A 中调用此方法时,它在 A 中的链接很好,在 B 中的链接也很好。
有任何想法吗 ?
最佳答案
关于c++ - 模板类给出链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4583816/