Using #define once for multiple source files

Is there a way in Visual C ++ for #define something in the cpp file and define it in other cpp files?

+3
source share
4 answers

There are at least two options:

  • Put the definition in the header file and include this header file in all the source files where you need the definition
  • Use the parameter /Dfor the compiler to define the macro (this can also be set in the project properties under C / C ++ → Preprocessor → Preprocessor Definitions )
+13
source

definitions.h:

#define foo bar

class.h:

#include "definitions.h"
+2

#define (.h) #include, .cpp.

+1

- .

.cpp, , , : C/++ → →

.cpp, .

0

Source: https://habr.com/ru/post/1747908/