1

If I write something such as this:

class myclass { #define ADD(x,y) {return x+y} public: } 

is the define private to my class?

note that I am defining it in *.hpp and I want to make sure that if I include this hpp to another source code, the other source code don't have access to this define.

Is there any better solution than using #define in C++ which can do the same thing?

What about using? is it private to my class or not?

class myclass { using std; public: } 
10
  • 1
    Possible duplicate of: stackoverflow.com/questions/6379489/… Commented Jun 28, 2016 at 16:08
  • @DeathTails Thanks, that one if for C, and this is for c++, are they the same? Commented Jun 28, 2016 at 16:10
  • 1
    In this case, yes. The answer, and the reasons behind it, are exactly the same. Commented Jun 28, 2016 at 16:13
  • @PaulRoub Think we should dual tag that Q to use it as a dupe target for both languages? Commented Jun 28, 2016 at 16:16
  • 1
    Please only ask one question per question. The question on using using should be its owns question. Commented Jun 28, 2016 at 16:36

2 Answers 2

6

It is not, and can never be.

All preprocessor commands (#...) are processed before the source code is ever read and analyzed, so it does not matter at all where you put them; only the sequence (if they build on each other) and the relative position to their usage (before/after) matters.

You can imagine preprocessor commands to be something like a 'find/replace from here on'.

Sign up to request clarification or add additional context in comments.

Comments

0

You may use #undef to limit the scope of a #define. Perhaps you could even use it to limit the scope of a define which you yourself did not create.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.