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等,一起编译了吗·
    
    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧