头文件可以在主类中运行。这怎么可能?

Kal*_*ana 2 c c++ header

当我使用 C 编程时,通常的include方法是

#include<stdio.h>
int main()
{
    printf("Hello World");

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

Output: Hello World

现在我试图将我的#include放入我的主类并且它完美地运行而没有任何错误或警告。

int main()
{
    #include <stdio.h>
    printf("Hello World\n");

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

Output: Hello World

我已经用C++. 我不能在那里做那种活动,它给了我很多错误。

为什么只有C这个技术?
这怎么可能?

Gau*_*gal 6

如这里所见,内部cdefs.h __BEGIN_DECLS定义为

#ifdef        __cplusplus
#define __BEGIN_DECLS        extern "C" {
#define __END_DECLS        }
#else
#define __BEGIN_DECLS
#define __END_DECLS
#endif
Run Code Online (Sandbox Code Playgroud)

这__BEGIN_DECLS是在使用stdio.h所看到这里

因为C++,__BEGIN_DECLS扩展到extern "C"和链接规范应该在全局范围内而不是在内部main