1

I bumped in to an error when trying to overload operator =

Not sure what is wrong with the code. Thanks for help!

Here is my code:

matrix.h

namespace MATRIX{
  class Matrix{
      // other private methods
      public:
          // other public methods
          template < typename T >
          Matrix& operator=(std::list<T> & data) ;
  }
};

matrix.cu

namespace MATRIX{
   // other definitions
   template < typename T >
   Matrix& Matrix::operator=(list<T> & data) {
       // method definition
   }
}

test.cu

#include <list>
#include "matrix.h"
// other includes
int main(void){
    using namespace std;
    using MATRIX::Matrix;
    Matrix k_matrix;
    list<double> k_list(100);
    // initialize k_list
    k_matrix = k_list;
}

Build

nvcc -c matrix.cu
nvcc -o test test.cu matrix.o

Error on second command

 tmpxft_00001f0f_00000000-3_test.cudafe1.cpp:(.text+0x202): 
 undefined reference to`MATRIX::Matrix& MATRIX::Matrix::operator=<double> 
 (std::list<double, std::allocator<double> >&)'
user2684645
  • 501
  • 1
  • 7
  • 15

0 Answers0