job interview question -data structures [closed]
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 once
s. 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.
精彩评论