如何编写内联包含

How to write an inline include

本文关键字:包含 何编写      更新时间:2023-10-16

我知道在Java中下面的两个代码示例做同样的事情,我想知道是否有可能在c++中做类似的事情。

// At the top
import System.out.println;
// In a function
        println(" :) ");

// Directly in a function
        System.out.println(" :) ");

例如,在c++中,我想把这个变成:

#include<time.h>
int main ()
{
    clock_t started;

变成这样:

int main ()
{
    (time.h)::clock_t started;

这在c++中可能吗?如果有,谁能举个例子?

不,这不可能。#include指令由称为预处理器的单独"实体"处理,虽然它不是一个单独的程序,但它是编译器的不同组件,在编译代码之前"运行",并处理宏,#pragma等。它没有模块的概念

源文件边界在c++中并不重要——一个特定的声明出现在某个文件中没有任何意义。

您可能正在寻找名称空间。

相关文章: