Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ #include - Only partial #include

Tags:

c++

include

Sometimes I run into situation where I find that I need to make an #include to large third party file just so I can use one function or a small class and that makes me feel guiltiy as I know that this is gone increase my compile time as it will complie the whole file when I just wanted that one function. Is there any way to get around this and only include that one function that I want without rewriting the whole thing?

like image 273
Caesar Avatar asked Jul 09 '12 20:07

Caesar


1 Answers

You have some options:

  • Just include the header. Really, it won't increase your compile time by that much.
  • Complain to your 3rd-party header provider. Tell them to ship smaller, more modular headers.
  • Don't include the header, but declare as extern the single function you care about, like so extern int GetMeaningOfLife(int mice);
like image 193
Robᵩ Avatar answered Oct 12 '22 05:10

Robᵩ