I was wondering if I could import a header file, but not include any of that header file’s included headers.
Suppose I have Class A that imports Class B. In Class B, I import Class C. Is there any way I can hide Class C from Class A?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, you cannot do that: once you import a file, all its imports come in as well.
However, if you want to use only
ClassA, you can forward-declare it in your own header, instead of importingClassA‘s header:Now you can make variables of type
ClassA*, useClassA*as return type or a parameter type, etc. At the same time, dependencies ofClassA‘s header will not be loaded.In general, it is a good idea to reduce the number of headers that you import inside your header, for example by moving imports related to implementation (rather than the interface) into the .m file, and using class extensions.