【发布时间】:2016-08-30 15:30:17
【问题描述】:
只是风格问题,甚至可能是我不知道的不当行为。
我目前正在编写我的第一个软件,将由我以外的人使用和审查。当我编写代码并调用头文件时,跨文件多次调用同一个头文件是不好的做法。
例如
exampleClass.h
#ifndef BUG_H
#define BUG_H
#include<string>
class Bug{
private:
int bug_id; //6 digit int
Date creation_ts; //Date object containing time of creation
std::string short_desc; //Short description of bug
std::string classification; //Catagory of bug_id
std::string product; //What product is the bug regarding
std::string component
}
#endif
anotherExample.h
#ifndef ANOTHEREXAMPLE_H
#define ANOTHEREXAMPLE_H
#include<string>
class Pug{
private:
int bug_id; //6 digit int
Date creation_ts; //Date object containing time of creation
std::string short_desc; //Short description of bug
std::string classification; //Catagory of bug_id
std::string product; //What product is the bug regarding
std::string component
}
#endif
如果两个不同的头文件都具有依赖关系,那么在两个不同的头文件中包含两次字符串有什么问题吗?这会在软件生命周期的后期导致错误吗?
【问题讨论】:
-
<string>很可能有自己的header include guard。
标签: c++ include libraries include-guards