RequiemZ 2015-05-27 07:21 采纳率: 0%
浏览 3775

VS2013 C++ error LNK2019: 无法解析的外部符号

#include
#include
#include
using namespace std;
#include
template
class CMatrix
{
T * * Mat;
int nRow;
int nCol;
public:
CMatrix();
CMatrix(int row, int col);
CMatrix(int row, int col, int k);
void Show();
void InputFromFile();
friend CMatrixoperator (CMatrix &mat1, CMatrix &mat2);
};
template
CMatrix::CMatrix()
{
nRow = 100, nCol = 100;
Mat = new T
[100];
for (int i = 0; i {
Mat[i] = new T[100];
}
}
template
CMatrix::CMatrix(int row, int col)
{
int i, j;
nRow = row, nCol = col;
Mat = new T*[nRow];
for (i = 0; i {
Mat[i] = new T[nCol];
}
cout for (i = 0; i for (j = 0; j {
cout cin >> Mat[i][j];
}
}
template
CMatrix::CMatrix(int row, int col, int k)
{
nRow = row, nCol = col;
Mat = new T*[nRow];
for (int i = 0; i {
Mat[i] = new T[nCol];
}
}
template
void CMatrix::Show()
{
int i, j;
for (i = 0; i {
cout for (j = 0; j cout }
cout }
template
void CMatrix::InputFromFile()
{
ifstream infile;
infile.open("daijp.txt", ios::_Nocreate);
if (!infile)
{
cout << "输入文件不存在,请先建立输入文件\n";
exit(0);
}
for (int i = 0; i for (int j = 0; j {
infile >> Mat[i][j];
}
infile.close();
}
template
CMatrix operator* (CMatrix &mat1, CMatrix &mat2)
{
CMatrix mat3(mat1.nRow, mat2.nCol, 0);
for (int i = 0; i for (int j = 0; j {
mat3.Mat[i][j] = 0;
for (int k = 0; k mat3.Mat[i][j] += mat1.Mat[i][k] * mat2.Mat[k][j];
} return mat3;
} template
void choose1(T)
{
cout << "1)初始化赋值" << endl << "2)键盘输入" << endl << "3)文件输入" << endl;
int srfs;
cout << "请选择数据输入方式:\n";
cin >> srfs;
switch (srfs)
{
case 1:
{
CMatrix mata, matb, matc;
}break;
case 2:
{
int a, b, c, d;
cout << "请输入第一个矩阵的行数和列数:" << endl;
cin >> a >> b;
CMatrix mata(a, b);
cout << "请输入第二个矩阵的行数和列数:" << endl;
cin >> c >> d;
if (b != c)
{
cout << "错误!!!两矩阵不能相乘!!!\n";
break;
}
CMatrix matb(c, d);
CMatrix matc(a, d, 0);
mata.Show();
matb.Show();
matc = mata*matb;
cout << "两矩阵相乘结果为:\n";
matc.Show();
}break;
case 3:
{
int a, b, c, d;
cout << "请输入第一个矩阵的行数和列数:" << endl;
cin >> a >> b;
CMatrix mata(a, b, 0);
cout << "请输入第二个矩阵的行数和列数:" << endl;
cin >> c >> d;
if (b != c)
{
cout << "错误!!!两矩阵不能相乘!!!\n";
break;
}
CMatrix matb(c, d, 0);
CMatrix matc(a, d, 0);
mata.InputFromFile();
matb.InputFromFile();
mata.Show();
matb.Show();
matc = mata*matb;
cout << "两矩阵相乘结果为:\n";
matc.Show();
}break;
default:cout << "输入选择错误!!!" << endl;
}
}
void choose()
{
cout << "作者:周毅" << setw(32) << "学号:140604163" << setw(32) << "专业:软件工程" << endl;
cout << endl << "1)整型" << endl << "2)浮点型" << endl << "3)双精度型" << endl;
cout << "请选择数据类型:\n"; int sjlx; cin >> sjlx; switch (sjlx) { case 1: { choose1(1); }break; case 2: { choose1(0.0); }break; case 3: { choose1(1e-10); }break; default:cout << "输入选择错误!!!" << endl; } cout << endl;
}
void main()
{
loop:
cout << " ***************************************************************\n";
cout << " ******************************************\n";
cout << " ***************";
cout << "\n\n\n************************欢迎使用矩阵乘法计算程序!*************************\n";
cout << " ***************\n";
cout << " ******************************************\n";
cout << " ***************************************************************\n\n";
choose();
loop1:
cout << "想继续执行吗?" << endl << "1)继续" << endl << "2)退出" << endl;
int a;
cin >> a;
switch (a)
{
case 1:
goto loop;
break;
case 2:
{
cout << "非常感谢您的使用!!!" << endl;
cout << "按任意键退出……" << endl;
cin.get();
cin.get();
exit(1);
}
default:cout << "输入选择错误!!!" << endl;
goto loop1;
}
}

1> JB.cpp
1>JB.obj : error LNK2019: 无法解析的外部符号 "class CMatrix __cdecl operator*(class CMatrix &,class CMatrix &)" (??D@YA?AV?$CMatrix@H@@AAV0@0@Z),该符号在函数 "void __cdecl choose1(int)" (??$choose1@H@@YAXH@Z) 中被引用
1>JB.obj : error LNK2019: 无法解析的外部符号 "class CMatrix __cdecl operator*(class CMatrix &,class CMatrix &)" (??D@YA?AV?$CMatrix@N@@AAV0@0@Z),该符号在函数 "void __cdecl choose1(double)" (??$choose1@N@@YAXN@Z) 中被引用
1>F:\C++\ZYB\Debug\ZYB.exe : fatal error LNK1120: 2 个无法解析的外部命令

  • 写回答

6条回答

  • oyljerry 2015-05-27 07:24
    关注
    你的类实现的cpp等,一起编译了吗·
    
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!