首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

CVector和CMatrix重定义异常?

2012-03-16 
CVector和CMatrix重定义错误???/************************************************本程序来源于黄振侃数

CVector和CMatrix重定义错误???
/*    
          ***********************************************

        本程序来源于   黄振侃   数值计算-微分方程数值解   北京工业大学出版社   2006年10月

          ***********************************************
*/
//向量类(CVector)与矩阵类(CMatirx)的声明与实况适两个基础类,后面的很多算法   都用到了这两个类。
//Matrix.h:向量类的声明
#define   NULL   0
#define   DEFAULT_NUM   5  
#define   EPSILON   1e-6
#include <math.h>
//n的阶乘,为避免溢出返回值用double型
double   Factorial(int   n);
//c(m,n)的组合数,为避免溢出返回值用double型
double   Combination   (int   m,int   n);
//求x的n次方,当x=0时,无论n为什么值,返回值都是0
double   Mypower(double   x,int   n);

//向量(数组)类,下标从0开始
class   CVector
{
public:
CVetcot(int   size=DEFAULT_NUM);//构造函数
Cvector(CVector&   v);//拷贝构造函数
virtual   ~CVector();//析构函数  
public:
double   &operator[](int   index);//重载[]运算符
CVector&   operator=(CVector   &v);//重载=运算符
void   Resize(int   new_size);//重新定义向量元素个数  
void   Print();//打印向量  
int   GetSize(){return   m_nSize;}//取得数组的长度和缓冲区地址
double   *GetData(){return   m_pdData;}
private:
double*   m_pdData;//指向向量使用的内存缓冲区
int   m_nSize;//元素个数
double   m_nDummy;//下标出界时,返回的元素
};  


//矩阵类,下标从0开始矩阵
class   CMatrix
{
public:
CMatrix(int   rows=DEFAULT_NUM,int   cols=DEFAULT_NUM);//构造函数,应有缺省值
CMatrix(CMatrix   &m);//拷贝构造函数
virtual   ~CMatrix();//析构函数
public:
CVector   &operator[]   (int   inedex);//重载[]运算符
CMatrix   &operator   =   (CMatrix&   m);//重载=运算符
void   Resize(int   new_rows,int   new_cols);//改变矩阵的大小
void   Print();//   打印矩阵
CMatrix   GetNagtiveMatrix();//得到逆矩阵
//
int   GetRow(){return   m_nRows;}
int   GetCol(){return   m_nCols;}
//
friend   CMatrix   operator*   (CMatrix&   a,CMatrix&   b);//重载矩阵乘法运算
private:
CVector*   m_paryData;//矩阵行向量的指针数组
int   m_nRows,m_nCols;//矩阵的行数,列数
void   SetData(CMatrix&   m);//复制已知矩阵到自身
};


错误如下:
Compiling...
Euler.cpp
c:\matrix.h(23)   :   error   C2011:   'CVector '   :   'class '   type   redefinition
c:\matrix.h(45)   :   error   C2011:   'CMatrix '   :   'class '   type   redefinition


[解决办法]
这种错误可能是由于头文件被多次include
可以在matrix.h文件中以下代码:
#ifndef MATRIX_H
#define MATRIX_H

.....这里加上matrix.h文件原来的内容

#endif

热点排行