2010-02-19 128 views
0

下面的代碼鏈接錯誤LNK2019,而試圖在嘗試編譯成編譯模板聲明

#include <iostream> 
    #include <conio.h> 

    using namespace std; 

    template <typename T> class grid 
    { 
    public: 
     grid(); 
     ~grid(); 
     void createCells(); 
    private: 
     T **cells; 
    }; 

int main(int argc, char **argv) 
    { 
     grid<int> intGrid; 
     _getch(); 
     return 0; 
    } 

PROG - 得到了一個消息:

1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall 
grid<int>::~grid<int>(void)" ([email protected]@@[email protected]) referenced in function _main 
1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall 
grid<int>::grid<int>(void)" ([email protected]@@[email protected]) referenced in function _main 

什麼需要做什麼?

回答

1

您需要定義構造函數和析構函數(你只是宣佈他們):

template <typename T> class grid 
{ 
public: 
    grid() 
    {} // here 
    ~grid() 
    {} // and here 
    void createCells(); 
private: 
    T **cells; 
}; 
+0

謝謝,編譯了! – zed91 2010-02-19 07:23:35