2014-01-23 64 views
0

我無法創建LO類的對象。代碼如下。創建對象時未定義的引用

Tem.h 
    #ifndef TEM_H_ 
    #define TEM_H_ 

    #include <iostream> 
    #include <exception> 
    #include "UDPTest.h" 

    template<class T> 
    class Tem : public std::exception { 
    public: 
    T* UDPt; 
    Tem(T& t) throw(); 
    virtual ~Tem() throw(); 
    }; 

    template<class T> 
    class LO :public Tem<T> { 
    char* mez; 
    public: 
    LO() throw() ; 
    char* what() const throw(); 
    virtual ~LO() throw(); 
    }; 

    template<class T> 
    class AT :public Tem<T>{ 
    char* mez; 
    public: 
    AT() throw(); 
    char* what() const throw(); 
    virtual ~AT() throw(); 
    }; 
    #endif /* TEM_H_ */ 



Tem.cpp 



#include "Tem.h" 
#include <iostream> 
using namespace std; 


template<class T> 
Tem<T>::Tem(T& t) throw() : exception(){ 
UDPt = t; 
// TODO Auto-generated constructor stub 
} 
template<class T> 
Tem<T>::~Tem() throw() { 
// TODO Auto-generated destructor stub 
} 

template<class T> 
LO<T>::LO() throw() { 
cout<<"LO constructor"<<endl; 
} 
template<class T> 
LO<T>::~LO() throw(){ 
} 
template<class T> 
char* LO<T>::what() const throw(){ 
return "Lockout validation failed."; 
} 

template<class T> 
AT<T>::AT() throw(){ 
cout<<"AT validation failed."<<endl; 
} 
template<class T> 
char* AT<T>::what() const throw(){ 
return "Active Task validation failed."; 
} 
template<class T> 
AT<T>::~AT() throw(){ 
} 





UDPTest.h 


#ifndef UDPTEST_H_ 
#define UDPTEST_H_ 

class UDPTest { 
public: 
int udp; 
int tcp; 
UDPTest(); 
virtual ~UDPTest(); 

}; 

#endif /* UDPTEST_H_ */ 




templatetest.cpp 

#include <iostream> 
#include "Tem.h" 
#include "UDPTest.h" 
//#include <exception> 
using namespace std; 

int main() { 
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!! 
try{ 
    throw LO<int>(); 
    //LO<int> loo; 
}catch(exception& e){ 
    cout<<"got"; 
} 
return 0; 
} 
在主函數我建立LO類對象和投擲

,LO類繼承TEM類,這是模板,TEM類內部我有UDPTest類的指針。

據我所知,我做錯了某處,但我無法知道。請幫我

感謝

+0

有未定義的引用錯誤,我在哪裏投擲物體。我不知道發生了什麼問題。 –

回答

相關問題