c++ - 模板类无法正确构建

标签 c++ templates static-libraries

标题

class linkNode {
    public:
        linkNode(void *p) {
            before = 0;
            after = 0;
            me = p;
        }

        linkNode *before;
        void *me;
        linkNode *after;
    };

    template <class T>
    class list
    {
    public:
        list(void) { first = last = NULL; size = 0; }
        ~list(void) { while(first) deleteNode(first); }      
    private:
        void deleteNode(linkNode *l);

        linkNode *first, *last;
        unsigned int size;
    };

.Cpp

template <class T>
inline void list<T>::deleteNode(linkNode *l) {
    if(c->before)
        if(c->after) {
            c->before->after = c->after;
            c->after->before = c->before;
        } else
            c->before->after = last = NULL;
    else
        if(c->after)
            c->after = first = NULL;
    delete c; size--;
}

我将此设置为构建为 .lib,并且构建良好。当我尝试 ePhys::list<int> myList;我收到一个链接器错误,说它找不到 ePhys::list<int>::deleteNode(class ePhys::linkNode *)这不是使用库设置的问题,我已经用其他虚拟类进行了测试。

我正在使用 MSVC 2010 测试版。

有什么方法可以使它正确链接吗?

最佳答案

C++ 并不真正支持模板的单独编译 - 您需要将所有模板代码放在头文件中。

关于c++ - 模板类无法正确构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2295582/

相关文章:

c++ - 未知类型名称错误Qt C++

c++ - 如何在用户选择选项后使用 switch 语句进行函数调用?

c++ - 试图更好地理解 std::forward、std::move

c++ - 乱序模板参数规范/推导是否可能?

c++ - 为什么我的静态库这么大?

c++ - 模板矩阵模板

c++ - 致命字符串错误

vba - 出现编译错误: User-defined type not defined when working to make an old 32-bit template into a Word 2012 64-bit template

c++ - 32 位 arm 处理器上的链接错误 : "Cannot find -ltinfo" on Ubuntu 12. 04

linker - Xamarin.iOS 链接器为临时删除 i386