Only include file in some cases? (c++)

Started by
4 comments, last by suliman 5 years, 8 months ago

Can i control it so this include is only made in the project depending on a define? The inclusion adds need for dll, paths and other stuff i dont use in all projects so i would want to toggle it on/off

I know this is not the syntax but you get the idea:


#define ADV_MODE 1

if (ADV_MODE)
   #include <advLibrary.h>

 

Advertisement

Sure you can, and it usually takes the form:


#ifdef USE_HEADER_H
#include <header.h>
#endif

 

That's quite close to it!

 

What you are looking for is the "ifdef" preprocessor directive


#ifdef ADV_MODE
   #include <advLibrary.h>
#endif

Or, if you actually want to use its value, a regular "if"


#if ADV_MODE == 1
    #include <advLibrary.h>
#endif

 

#define k 1

#undef k or #define k 0

#ifndef k

#ifdef k

#elseif

Thanks!

This topic is closed to new replies.

Advertisement