开发者

problems using a class template

i created a template that contains a map. when i try to create an instance of that template i encounter a linking problem with the constructor and destructor. also, when i try to create an instance in main it skips the line while debugging, and doesn't even show it in the locals list. it doesn't compile "DataBase db;" unless i add "(开发者_如何学Go)" after db. (that's the way i try to initiate the instance in main).

the code:

h:

template <class keyVal,class searchVal, class T>  
class DataBase  
{  
private:  
    map<keyVal,pair<searchVal,T*>*> DB;  
public :  
    DataBase();  
    virtual ~DataBase();    
}; 

cpp:

#include "DataBase.h"  

template <class keyVal,class searchVal, class T>  
DataBase<keyVal,searchVal,T>::DataBase()  
{}  

template <class keyVal,class searchVal, class T>  
DataBase<keyVal,searchVal,T>::~DataBase()  
{}

thanks


Add the implementation of template classes (and functions) directly in the header file:

template <class keyVal,class searchVal, class T>  
class DataBase  
{  
private:  
    map<keyVal,pair<searchVal,T*>*> DB;
public :  
    DataBase() {};  
    virtual ~DataBase() {};    
}; 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜