c++ - Do I need to redefine preprocessor defines in parent projects? -


maybe since not find right keywords, unable clarify doubt on google.

let have 2 c++ projects; proja , projb. in exmpl.h file in proja, there condition:

class myclass { ... #ifdef myvar virtual ~myclass() {} #endif } 

i define myvar project setting , compile proja generate proja.a static library.

now, projb, need use exmpl.h of proja. include , compile projb using proja.a static library.

however, imagine in projb did not define myvar.

  • what happen in case? projb skip code within #ifdef, uses static library compiled code within #ifdef?

  • so, error , cause unexpected behavior?

  • do have define preprocessor defines used in sub-projects, in projects use them?

thanks.

the definitions of myclass used in both projects must same, otherwise it's violation of one definition rule, causing undefined behavior, no diagnostic required (that is, compiler isn't required tell violation).

so yes, must define myvar in projb, other defines affecting definitions used in both projects.

this applies of course, entities odr-used in both projects.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo