error c1001问题

newtocsdn 2004-12-06 07:27:23
错误信息:
Deleting intermediate files and output files for project '4_5 - Win32 Debug'.
--------------------Configuration: 4_5 - Win32 Debug--------------------
Compiling...
4_5.cpp
f:\c++\test\4_5\matrix.h(8) : fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'msc1.cpp', line 1786)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
Matrix.cpp
f:\c++\test\4_5\matrix.h(8) : fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'msc1.cpp', line 1786)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
Error executing cl.exe.

4_5.exe - 2 error(s), 0 warning(s)

Matrix.h文件:
#include <iostream>
using namespace std;

typedef float elemType;

class Matrix
{
friend Matrix operator+(const Matrix&,const Matrix&);
friend Matrix operator*(const Matrix&,const Matrix&);

public:

Matrix(const elemType*);
Matrix(elemType=0.,elemType=0.,elemType=0.,elemType=0.,
elemType=0.,elemType=0.,elemType=0.,elemType=0.,
elemType=0.,elemType=0.,elemType=0.,elemType=0.,
elemType=0.,elemType=0.,elemType=0.,elemType=0.,);

int rows() const {return 4;}
int cols() const {return 4;}

ostream& print (ostream&) const;

void operator+=(const Matrix&);

elemType operator()(int row,int column) const
{
return _matrix[row][column];
}

elemType& operator()(int row,int column)
{
return _matrix[row][column];
}

private:
elemType _matrix[4][4];

};

Matrix.cpp文件:
#include "Matrix.h"
#include <iostream>

Matrix operator+(const Matrix &m1,const Matrix &m2)
{
Matrix result(m1);
result+=m2;
return result;
}

Matrix operator*(const Matrix &m1,const Matrix &m2)
{
Matrix result;
for (int ix=0;ix<m1.rows();ix++)
for (int jx=0;jx<m1.cols(),jx++)
{
result(ix,jx)=0;
for(int kx=0;kx<m1.cols();kx++)
result(ix,jx)+=m1(ix,kx)*m2(kx,jx);
}
return result;
}

void Matrix::operator += (const Matrix &m)
{
for(int ix=0;ix<4;++ix)
for(int jx=0;jx<4;jx++)
_matrix[ix][jx]+=m._matrix[ix][jx];
}

ostream& Matrix::print(ostream &os) const
{
int cnt=0;
for(int ix=0;ix<4;++ix)
for(int jx=0;jx<4;++jx,++cnt)
{
if(cnt && !(cnt%8))
os<<endl;
os<<_matrix[ix][jx]<<' ';
}
os<<endl;
return os;
}

Matrix::Matrix(const elemTypr *array)
{
int array_index=0;
for(int ix=0;ix<4;++ix)
for(int jx=0;jx<4;++jx)
_matrix[ix][jx]=array[array_index++];
}

Matrix::Matrix(
elemType a11,elemType a12,elemType a13,elemType a14,
elemType a21,elemType a22,elemType a23,elemType a24,
elemType a31,elemType a32,elemType a33,elemType a34,
elemType a41,elemType a42,elemType a43,elemType a44,)

{
_matrix[0][0]=a11;_matrix[0][1]=a12;_matrix[0][2]=a13;_matrix[0][3]=a14;
_matrix[1][0]=a21;_matrix[1][1]=a22;_matrix[1][2]=a23;_matrix[1][3]=a24;
_matrix[2][0]=a31;_matrix[2][1]=a32;_matrix[2][2]=a33;_matrix[2][3]=a34;
_matrix[3][0]=a41;_matrix[3][1]=a42;_matrix[3][2]=a43;_matrix[3][3]=a44;
}

main文件:
#include "Matrix.h"
#include "Matrix.h"
#include <iostream>

inline ostream& operator<<(ostream& os,const Matrix &m)
{
return m.print(os);
}

int main()
{
Matrix m;
cout<<m<<endl;

elemType ar[16]={
1.,0.,0.,0.,0.,1.,0.,0.,
0.,0.,1.,0.,0.,0.,0.,1.}

Matrix identity(ar);
cout<<identity<<endl;

Matrix m2(identity)
m=identity;
cout<<m2<<endl;
cout<<m<<endl;

elemType ar2[16]={
1.3,0.4,2.6,8.2,6.2,1.7,1.3,8.3,
4.2,7.4,2.7,1.9,6.3,8.1,5.6,6.6};

Matrix m3(ar2);
cout<<m3<<endl;

Matrix m4=m3*identity;
cout<<m4<<endl;

Matrix m5=m3+m4;
cout<<m5<<endl;

m3+=m4;
cout<<m3<<endl;
}
根据错误信息查得信息:
Visual C++ Concepts: Building a C/C++ Program

Fatal Error C1001
INTERNAL COMPILER ERROR
(compiler file file, line number)

The compiler cannot generate correct code for a construct, probably due the combination of an expression and an optimization option. Try removing one or more optimization options and recompiling the function containing the line indicated in the error message.

You can probably fix the problem by removing one or more optimization options. To determine which option is at fault, remove options one at a time and recompile until the error message goes away. The options most commonly responsible are /Og, /Oi, and /Oa. Once you determine which option is responsible, you can disable it using the optimize pragma around the function where the error occurs and continue to use the option for the rest of the module.

Try rewriting the line where the error is reported, or several lines of code surrounding that line. If that doesn't work, contact Microsoft Product Support Services.

看了这个和没有看
没有什么区别
各位一般遇到问题怎么解决呀
也查msdn在线吗 ??
...全文
229 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
newtocsdn 2004-12-06
  • 打赏
  • 举报
回复
修改后的程序:
Matrix.h文件:
#include <iostream>
using namespace std;

typedef float elemType;

class Matrix;

Matrix operator+(const Matrix&,const Matrix&);
Matrix operator*(const Matrix&,const Matrix&);

class Matrix
{

friend Matrix operator+(const Matrix&,const Matrix&);
friend Matrix operator*(const Matrix&,const Matrix&);

public:

Matrix(const elemType*);
Matrix(elemType=0.,elemType=0.,elemType=0.,elemType=0.,
elemType=0.,elemType=0.,elemType=0.,elemType=0.,
elemType=0.,elemType=0.,elemType=0.,elemType=0.,
elemType=0.,elemType=0.,elemType=0.,elemType=0.);

int rows() const {return 4;}
int cols() const {return 4;}

ostream& print (ostream&) const;

void operator+=(const Matrix&);

elemType operator()(int row,int column) const
{
return _matrix[row][column];
}

elemType& operator()(int row,int column)
{
return _matrix[row][column];
}

private:
elemType _matrix[4][4];

};

Matrix.cpp文件:
#include "Matrix.h"
#include <iostream>

Matrix operator+(const Matrix &m1,const Matrix &m2)
{
Matrix result(m1);
result+=m2;
return result;
}

//Matrix operator(const Matrix &m1,const Matrix &m2)
//{
// Matrix result;
// for(int ix=0;ix<4;++ix)
// for(int jx=0;jx<4;++jx)
// result.m[ix][jx]=m1.m[ix][jx]+m2.m[ix][jx];
//
// return result;
//}

Matrix operator*(const Matrix &m1,const Matrix &m2)
{
Matrix result;
for (int ix=0;ix<m1.rows();ix++)
for (int jx=0;jx<m1.cols();jx++)
{
result(ix,jx)=0;
for(int kx=0;kx<m1.cols();kx++)
result(ix,jx)+=m1(ix,kx)*m2(kx,jx);
}
return result;
}

void Matrix::operator += (const Matrix &m)
{
for(int ix=0;ix<4;++ix)
for(int jx=0;jx<4;jx++)
_matrix[ix][jx]+=m._matrix[ix][jx];
}

ostream& Matrix::print(ostream &os) const
{
int cnt=0;
for(int ix=0;ix<4;++ix)
for(int jx=0;jx<4;++jx,++cnt)
{
if(cnt && !(cnt%8))
os<<endl;
os<<_matrix[ix][jx]<<' ';
}
os<<endl;
return os;
}

Matrix::Matrix(const elemType *array)
{
int array_index=0;
for(int ix=0;ix<4;++ix)
for(int jx=0;jx<4;++jx)
_matrix[ix][jx]=array[array_index++];
}

Matrix::Matrix(
elemType a11,elemType a12,elemType a13,elemType a14,
elemType a21,elemType a22,elemType a23,elemType a24,
elemType a31,elemType a32,elemType a33,elemType a34,
elemType a41,elemType a42,elemType a43,elemType a44)

{
_matrix[0][0]=a11;_matrix[0][1]=a12;_matrix[0][2]=a13;_matrix[0][3]=a14;
_matrix[1][0]=a21;_matrix[1][1]=a22;_matrix[1][2]=a23;_matrix[1][3]=a24;
_matrix[2][0]=a31;_matrix[2][1]=a32;_matrix[2][2]=a33;_matrix[2][3]=a34;
_matrix[3][0]=a41;_matrix[3][1]=a42;_matrix[3][2]=a43;_matrix[3][3]=a44;
}
main文件:
#include "Matrix.h"
#include <iostream>

inline ostream& operator<<(ostream& os,const Matrix &m)
{
return m.print(os);
}

int main()
{
Matrix m;
cout<<m<<endl;

elemType ar[16]={
1.,0.,0.,0.,0.,1.,0.,0.,
0.,0.,1.,0.,0.,0.,0.,1.};

Matrix identity(ar);
cout<<identity<<endl;

Matrix m2(identity);
m=identity;
cout<<m2<<endl;
cout<<m<<endl;

elemType ar2[16]={
1.3,0.4,2.6,8.2,6.2,1.7,1.3,8.3,
4.2,7.4,2.7,1.9,6.3,8.1,5.6,6.6};

Matrix m3(ar2);
cout<<m3<<endl;

Matrix m4=m3*identity;
cout<<m4<<endl;

Matrix m5=m3+m4;
cout<<m5<<endl;

m3+=m4;
cout<<m3<<endl;

system("pause");
return 0;
}

newtocsdn 2004-12-06
  • 打赏
  • 举报
回复
To UPCC(杂食动物) :
改过以后编译通过
得到了想要的结果
谢了
不过
我还有个问题
为什么要把
class Matrix;
Matrix operator+(const Matrix&,const Matrix&);
Matrix operator*(const Matrix&,const Matrix&);
添加到定义类Matrix的前面呢???
Dong 2004-12-06
  • 打赏
  • 举报
回复
不是***************
即使加了class Matrix也没有用!!!
而是***************************
这个问题的解决方法是在定义类Matrix的前面加
class Matrix;
Matrix operator+(const Matrix&,const Matrix&);
Matrix operator*(const Matrix&,const Matrix&);
----------------------------------------------

我自己都看过了。
newtocsdn 2004-12-06
  • 打赏
  • 举报
回复
不行呀
即使加了class Matrix也没有用!!!
chunhai12 2004-12-06
  • 打赏
  • 举报
回复
INTERNAL COMPILER ERROR!
Dong 2004-12-06
  • 打赏
  • 举报
回复
error c1001问题
---------------------------
这个问题的解决方法是在定义类Matrix的前面加
class Matrix;
Matrix operator+(const Matrix&,const Matrix&);
Matrix operator*(const Matrix&,const Matrix&);


不过你定义的类有很多别的错误的

64,682

社区成员

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

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