help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Template Class ??


From: Sharwan Joram
Subject: Re: Template Class ??
Date: Sat, 6 Oct 2012 07:51:30 -0700 (PDT)
User-agent: G2/1.0

On Saturday, September 29, 2012 9:49:54 AM UTC+5:30, ArbolOne wrote:
> namespace jme {
> 
> template <class T> class Data {
> 
> private:
> 
>     T data;
> 
>     int id;
> 
> public:
> 
>     Data();
> 
>     Data(T, const int);
> 
>     virtual ~Data();
> 
>     Data(const Data& other);
> 
>     Data& operator=(const Data& other);
> 
>     const int getId();
> 
>     const T& getData() {
> 
>         return data;
> 
>     }
> 
> };
> 
> 
> 
> template <class T>
> 
> jme::Data<T>::Data() {}
> 
> 
> 
> template <class T>
> 
> jme::Data<T>::Data(T _data, const int _id) {
> 
>     this->data = _data;
> 
>     this->id = _id;
> 
> }
> 
> template <class T>
> 
> jme::Data<T>::~Data() {}
> 
> 
> 
> template <class T>
> 
> jme::Data<T>::Data(const Data& other) {
> 
>     //copy ctor
> 
> }
> 
> template <class T>
> 
> jme::Data<T>&
> 
> jme::Data<T>::operator=(const Data& rhs) {
> 
>     //if (this == &rhs) return *this; // handle self assignment
> 
>     //assignment operator
> 
>     this->T = rhs.T;
> 
>     //this->id = rhs.id;
> 
>     return *this;
> 
> }
> 
> template <class T>
> 
> const int jme::Data<T>::getId() {
> 
>     return id;
> 
> }
> 
> ---
> 
> int main(){
> 
>     jme::Data d;
> 
>     std::cout << "Hello world!" << std::endl;
> 
>     return 0;
> 
> }
> 
> 
> 
> The above program gives me this error message:
> 
> 
> 
> -------------- Build: Debug in data ---------------
> 
> 
> 
> Linking console executable: bin\Debug\list.exe
> 
> obj\Debug\main.o: In function `main':
> 
> C:/.../main.cpp:8: undefined reference to `jme::Data<std::string>::Data()'
> 
> 
> 
> C:/.../main.cpp:10: undefined reference to `jme::Data<std::string>::~Data()'
> 
> 
> 
> C:/.../main.cpp:10: undefined reference to `jme::Data<std::string>::~Data()'
> 
> 
> 
> collect2: ld returned 1 exit status
> 
> Process terminated with status 1 (0 minutes, 0 seconds)
> 
> 3 errors, 0 warnings
> 
>  
> 
> 
> 
> 
> 
> What am I doing wrong?

HTH--

I tried compiling the same at my machine, using Fedora Linux 17, gcc 4.7 , got 
this error:

test.cpp:47:15: error: missing template arguments before ‘d’
test.cpp:47:15: error: expected ‘;’ before ‘d’
test.cpp:48:5: error: ‘cout’ is not a member of ‘std’
test.cpp:48:36: error: ‘endl’ is not a member of ‘std’
test.cpp: At global scope:
test.cpp:50:1: error: expected ‘}’ at end of input

Changing : jme::Data <int> d; and including <iostream> makes it work !!


reply via email to

[Prev in Thread] Current Thread [Next in Thread]