求职面试问题——数据结构

发布于 2024-11-03 02:22:07 字数 193 浏览 1 评论 0原文

假设我有一组文件,并且每个文件中都有 include# 到同一组中的其他文件。假设我有加载某个文件中所有包含内容的函数。我需要编写加载某个给定源文件中所有包含内容的函数所以我将避免无限循环和循环调用包含。

为了解决这个问题,我必须使用这个函数,我不能使用 pragma 一次或类似的东西 我认为可以通过递归来解决,但我不确定如何解决,

谢谢

Suppose I have set of files and in every files there are include# to other files in the same set.Suppose I have function that load all the includes in certain file.I need to write function that load all the includes in some given source file so I will avoid infinite loop and circular call for the include.

To solve the question I have to use this function i can't use pragma once or something similar
I think it could be solved by recursion though I am not sure how

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

哭泣的笑容 2024-11-10 02:22:07

定义一个预处理器变量,通常为“CLASSNAME_H”,

检查该变量是否已定义,如果没有,则定义它并执行代码。例如:

#ifndef USER_H
#define USER_H

#include "Other.h"

class User { };

#endif

这就是你所说的,对吗?

Define a preprocessor variable, typically 'CLASSNAME_H'

Check to see if the variable is defined and, if not, then define it and execute the code. For example:

#ifndef USER_H
#define USER_H

#include "Other.h"

class User { };

#endif

This is what you're talking about, right?

人事已非 2024-11-10 02:22:07

来自 Wiki

在 C 和 C++ 编程语言中,#pragma Once 是一种非标准但广泛支持的预处理器指令,旨在使当前源文件在单个编译中仅包含一次。

From Wiki:

In the C and C++ programming languages, #pragma once is a non-standard but widely supported preprocessor directive designed to cause the current source file to be included only once in a single compilation.

嘿看小鸭子会跑 2024-11-10 02:22:07

我认为您想查看拓扑排序

I think that you want to look at Topological sorting.

故笙诉离歌 2024-11-10 02:22:07

从您的评论来看,您似乎无法对包含防护或#pragma Once使用正常检查。另一种方法是保存字符串中包含的每个文件的绝对(或相对)路径,如果再次遇到包含路径,则不包含该文件。

From your comments it seems you can't use the normal check for include guards or #pragma onces. Another way is to save the absolute (or maybe relative) path for every file you include in a string and if you encounter on of the include pathes again, don't include the file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文