[問題] linker error?
( *[1m *[m 為色碼,可以按 Ctrl+V 預覽會顯示的顏色 )
( 未必需要依照此格式,文章條理清楚即可 )
開發平台: (例: Dev-C++, Windows)
補充說明:
/*********************************************
.h檔
#ifndef MATRIX_H
#define MATRIX_H
#include "cmath"
template <class T>
class Matrix
{
public:
int nRow;
int nCol;
T **z;
Matrix();
};
#endif
**********************************************/
/**********************************************
.cpp檔
#include <iostream>
#include "Matrix.h"
template <class T>
Matrix<T>::Matrix()
{
this->nRow = 0;
this->nCol = 0;
this->z = NULL;
}
***********************************************/
int main(int argc, char *argv[])
{
Matrix <int> x;
system("PAUSE");
return EXIT_SUCCESS;
}
dev 出現
[Linker error] undefined reference to `Matrix<int>::Matrix()'
但是如果把.cpp的code寫在.h裡面
就可以正常編譯
請問這是什麼問題?
第一次用template
還請大家指點一下
謝謝大家
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.231.212
→
08/15 20:36, , 1F
08/15 20:36, 1F
→
08/15 20:45, , 2F
08/15 20:45, 2F
→
08/15 20:46, , 3F
08/15 20:46, 3F
→
08/15 20:51, , 4F
08/15 20:51, 4F
→
08/15 21:07, , 5F
08/15 21:07, 5F
→
08/15 21:09, , 6F
08/15 21:09, 6F
→
08/15 21:09, , 7F
08/15 21:09, 7F