2013-04-14 29 views
0

語境:我有它有兩個include條款一類:的#include重複

#ifndef VAR_RECORD_SONG_H 
#define VAR_RECORD_SONG_H 

#include "VarRecord.h" 
#include "Compressor.h" 

class VarRecordSong : public VarRecord 
{ 
    public: 
     VarRecordSong(); 
     ~VarRecordSong(); 
}; 

#endif /* VAR_RECORD_SONG_H */ 

問題:既VarRecord.hCompressor.h使用相同的文件GlobalConstants.h,如此明顯的編譯器抱怨。

+5

與[VarRecordSong.h]一樣,將[Include guard](http://en.wikipedia.org/wiki/Include_guard)放到'GlobalConstants.h'中? –

+0

@Haroogan大聲笑你是對的。謝謝。 –

回答

2

文件GlobalConstants.h應該是這樣的:

#ifndef GLOBAL_CONSTANTS_H 
#define GLOBAL_CONSTANTS_H 

file contents... 

#endif 

那麼該文件將只在預處理碼出現一次。