C/C++由於標頭檔案重複引入引起的成員或類重複定義的解決辦法
阿新 • • 發佈:2019-01-02
報錯資訊:
../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