2 qq 28527751 qq_28527751 于 2015.05.27 15:21 提问

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个回答

u012377333
u012377333   Rxr 2015.05.28 19:12

就是相应的函数定义没有链接到,相应的库函数或者是相应的cpp是不是都编译到了

xy707707
xy707707   2015.05.27 17:11

文件包含,,库文件是否齐全 。

VisualEleven
VisualEleven   Ds   Rxr 2015.05.27 17:34

你代码中有语法太多了~

qq_16794101
qq_16794101   2015.05.27 23:27

你代码中有语法太多了,文件包含,,库文件是否齐全 。

xy707707
xy707707   2015.05.28 08:35

文件包含,,库文件是否齐全 。

oyljerry
oyljerry   Ds   Rxr 2015.05.27 15:24
你的类实现的cpp等,一起编译了吗·
Csdn user default icon
上传中...
上传图片
插入图片