请教为什么我把main函数放在另一个文件里,引用另一个文件类的时候总出现连接错误

wangdy111 2009-02-28 01:55:31
这是//matrix。h
class CMatrix
{
private:
//double **mvalue;
int m_nRow;
int m_nCol;
public:
double **mvalue;
CMatrix();
CMatrix(int nRow,int nCol);
CMatrix(int nRow,int nCol,double dBuf);
CMatrix(const CMatrix &mat);
~CMatrix();
bool MatInv();
CMatrix operator*(const CMatrix&m);
CMatrix& operator*=(const CMatrix&m);
CMatrix& operator*=(double dBuf);
CMatrix operator*(double dBuf);
CMatrix operator+(const CMatrix&m);
CMatrix& operator+=(const CMatrix&m);
CMatrix& operator =(double dBuf);
CMatrix& operator=(const CMatrix&m);
CMatrix& Trans(const CMatrix&m);
void Realloc (int nRow,int nCol);
double & operator()(int iRow,int iCol)
{
return mvalue[iRow][iCol];
}

int GetCol() {return m_nCol;}
int GetRow() {return m_nRow;}
void setvalue();

};

//这是main,cpp
#include "matrix.h"
#include "iostream"
#include <stdio.h>

//--------------------
void main(){
CMatrix ss(2,2,0);
};


连接错误:
main.obj : error LNK2001: unresolved external symbol "public: __thiscall CMatrix::~CMatrix(void)" (??1CMatrix@@QAE@XZ)
main.obj : error LNK2001: unresolved external symbol "public: __thiscall CMatrix::CMatrix(int,int,double)" (??0CMatrix@@QAE@HHN@Z

...全文
120 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
touchwhat 2009-02-28
  • 打赏
  • 举报
回复
只要你把头文件添加了进去 VC都会看你有多少文件这样编译
wangdy111 2009-02-28
  • 打赏
  • 举报
回复
我的错误是不是只单独编译了main。cpp,没编译matrix。cpp
应该把main。cpp和matri。cpp放在一起编译并连接

touchwhat 2009-02-28
  • 打赏
  • 举报
回复
在你保存后的目录下的matrix是cpp类型把。。
wangdy111 2009-02-28
  • 打赏
  • 举报
回复
定义了
matrix。cpp
#include "math.h"
#include "memory.h"
#include "iostream"
#include "matrix.h"
CMatrix::CMatrix()
{
m_nRow=12;
m_nCol=12;
mvalue=new double* [12];
for(int ii=0;ii<12;ii++)
mvalue[ii]=new double [12];
}

CMatrix::CMatrix(int nRow,int nCol)
{
m_nRow=nRow;
m_nCol=nCol;
mvalue = new double* [nRow];
for(int ii=0;ii<nRow;ii++)
mvalue[ii]=new double [nCol];
}

CMatrix::CMatrix(int nRow,int nCol,double dBuf)
{
m_nRow=nRow;
m_nCol=nCol;
mvalue = new double* [nRow];
for(int ii=0;ii<nRow;ii++)
mvalue[ii]=new double [nCol];
for(ii=0;ii<nRow;ii++)
for(int jj=0;jj<nCol;jj++)
mvalue[ii][jj]=dBuf;
}

CMatrix::CMatrix(const CMatrix &m)
{
m_nRow=m.m_nRow;
m_nCol=m.m_nCol;
mvalue=new double* [m_nRow];
for(int ii=0;ii<m_nRow;ii++)
{
mvalue[ii]=new double[m_nCol];
memcpy(mvalue[ii],m.mvalue[ii],m_nCol*sizeof(double));
}
}

CMatrix::~CMatrix(void)
{
for(int ii=0;ii<m_nRow;ii++)
delete[] mvalue[ii];
delete[] mvalue;
}
其他略


我发现把#include“matrix。h”改成#include“matrix。cpp”就可以了,为什么呀
showcold 2009-02-28
  • 打赏
  • 举报
回复
没有matrix.cpp文件,工程->添加到工程->文件
pengzhixi 2009-02-28
  • 打赏
  • 举报
回复
CMatrix::~CMatrix(void)
CMatrix::CMatrix(int,int,double)应该是这两个函数没定义
pengzhixi 2009-02-28
  • 打赏
  • 举报
回复
CMatrix::~CMatrix(void)
CMatrix::CMatrix(int,int,double)
这两个函数你都没定义的吧
wangdy111 2009-02-28
  • 打赏
  • 举报
回复
那位朋友帮一下忙,急呀,困扰一天了,


高手们

救命

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧