gpt4 book ai didi

c++ - header 应包含一次

转载 作者:太空狗 更新时间:2023-10-29 23:24:18 24 4
gpt4 key购买 nike

在头文件中,我看到了两种定义宏的主要方法,以避免多次包含文件。

1.

#ifndef SOME_CLASS
#define SOME_CLASS
//code ...
#endif

2.

#ifndef SOME_CLASS
//code...
#define SOME_CLASS
#endif

哪个更好,为什么?

最佳答案

我更喜欢第一种方法,因为在 ifndef 之后发生什么并不重要,因为它会在之后直接定义。

关于c++ - header 应包含一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6123544/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com