C/C++由于头文件重复引入引起的成员或类重复定义的解决办法

报错信息:

../src/Circle.h:10:14: error: redefinition of 'PI'

const double PI=3.14159;

             ^

../src/Circle.h:10:14: note: previous definition is here

const double PI=3.14159;

             ^

In file included from ../src/继承与派生.cpp:12:

In file included from ../src/Tube.h:8:

../src/Circle.h:12:7: error: redefinition of 'Circle'

class Circle :public Point

      ^


解决办法:

在头文件前加上

//ifndef...endif 解决头文件重复引入问题

#ifndef CircleH

#define CircleH


头文件最末尾加上

#endif


你可能感兴趣的:(C/c++语言,C++BUILDER/RAD,Studio)