0

I am a new bee to template based programming and I have this error when compiling my project

error : multiple definition of Expr::Chapter_2<double>::get_pointer() 
objectfile.o:/Filename.h:42 first defined here.

The given code is entirely inside a .h header file. Any pointers to resolve this issue is highly appreciated.

code :

template< typename T >
class Chapter_2{

-------
public :
    inline T* get_pointer();
-------
};

// Function definitions
template< typename T >
T* Chapter_2<T>::get_pointer() {
    ------code------
}

// double specialization of template
template<>
double* Chapter_2<double>::get_pointer() {
    ------code------
}
user1801733
  • 147
  • 1
  • 3
  • 11

1 Answers1

0

Possible reasons:

1)In case You have your header not starting with #ifndef and you have included the same header twice or more.

2) In a cpp file where you are including the header containing the template, if you have again defined methods ( multiple definitions i.e., in cpp as well as in .h). The implementation of the methods in the template should be defined at the same place once.

Sanyam Goel
  • 2,138
  • 22
  • 40