开发者

job interview question -data structures [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and ca开发者_StackOverflow社区nnot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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


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?


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.


I think that you want to look at Topological sorting.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜