【问题标题】:#include repetition#包括重复
【发布时间】:2013-04-14 02:24:05
【问题描述】:

上下文:我有一个类有两个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,所以很明显编译器会报错。

【问题讨论】:

  • Include guard 放入GlobalConstants.h,就像您对VarRecordSong.h 所做的那样?
  • @Haroogan LOL 你是对的。谢谢。

标签: c++ include-guards


【解决方案1】:

文件 GlobalConstants.h 应该是这样的:

#ifndef GLOBAL_CONSTANTS_H
#define GLOBAL_CONSTANTS_H

file contents...

#endif

所以这个文件只会在预处理代码中出现一次。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-05
    • 2021-05-28
    • 2015-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多