我有在C++仿制药的问题,我有两个Matrix.h和Matrix.cpp files.Here是文件:成员函数
#pragma once
template<class T>
class Matrix
{
public:
static T** addSub(int size,T** firstMatrix,T** secondMatrix,int operation);
}
和Matrix.cpp
#include "Martix.h"
template<class T>
static T** Matrix<T>::addSub(int n,T **firstMatrix,T **secondMatrix,int operation)
{
//variable for saving result operation
T **result = new T*[n];
//create result matrix
for(int i=0;i<n;i++)
result[i] = new T[n];
//calculate result
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
result[i][j] =
(operation == 1) ? firstMatrix[i][j] + secondMatrix[i][j]:
firstMatrix[i][j] - secondMatrix[i][j];
return result;
}
当我运行这些我得到以下错误:
Error 1 error LNK2019: unresolved external symbol "public: static int * * __cdecl Matrix<int>::addSub(int,int * *,int * *,int)" ([email protected][email protected]@@[email protected]) referenced in function "public: static int * * __cdecl Matrix<int>::strassenMultiply(int,int * *,int * *)" ([email protected][email protected]@@[email protected]) C:\Users\ba.mehrabi\Desktop\Matrix\matrixMultiplication\main.obj matrixMultiplication
是什么问题?
您是否在声明的同一编译单元中使用了模板方法定义? – Simone
http://stackoverflow.com/questions/488959/how-do-you-create-a-static-template-member-function-that-performs-actions-on-a-te – Patrick
你拼错包括的名称文件。我想知道你是否在这里给我们提供真正的代码,或者如果你只是从内存中写下一些小说......另外,C++没有“泛型”。如果您来自Java背景,那么您可能会习惯于使用常见的C++习惯用法,这些习惯用法很不相同。例如,你应该很少或从不在C++中说'新'。 –