gpt4 book ai didi

c++ - #include 函数体内或降低其可见性

转载 作者:行者123 更新时间:2023-11-30 01:15:12 25 4
gpt4 key购买 nike

有没有办法缩小#include指令的范围?

我的意思是例如做这样的事情

void functionOneDirective()
{
#include "firstInstructionSet.h"
registerObject();

// cannot access instantiate()
}

void functionSecondDirective()
{
#include "secondInstructionSet.h"
instantiate();

// cannot access registerObject()
}

void main()
{
//cannot access instantiate() && registerObject()
}

最佳答案

不可能将“包含”限制为使用文件的一个子集。对于 include 之后的任何内容,它始终可见。

如果您有兴趣在某些功能上提供“不同”的观点,请考虑使用不同的命名空间来表达这些不同的“观点”。

关于c++ - #include 函数体内或降低其可见性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28874888/

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