Reputation: 13929
Is it possible to write define with spaces such as:
#define replace to replacement here
I want to replace "replace to" with "replacement here".
EDIT:
I want to test private members:
I did write
#define private public
but it didn't work for private slots in Qt
so my intend was to use something like
#define private slots: public slots:
anyway I have found another way to test slots and by the way I'm aware of that this is an ugly hack.
Upvotes: 17
Views: 26303
Reputation: 132994
no, you can't
#define identifier something
what you define must be an identifier which cannot contain space. Nor can it contain hyphen, begin with a number, etc. you can define only an identifier
what you wrote will work
#define replace to replacement here
but not as you expect. This line defined replace
to be substituted with to replacement here
Upvotes: 18
Reputation: 305
If you are doing unit test, you can compile your file with the following flag
-Dprivate=public
Then in your unit test, you will be able to call every private method of your class.
EDIT:
I've recently remarked that using the -fno-access-control flag on gcc compiler allows you to access private method or member. More info on that topic can be found here: Unit testing with -fno-access-control
Upvotes: 3
Reputation: 13007
You could do...
#define replace replacement
#define to here
Watch out for unintended side effects of the defines. You would probably want to #undef
them after they've done their job.
Upvotes: 7
Reputation: 14159
No, that's not possible. Why not just do this instead:
#define replace_to replacement here
Upvotes: 2
Reputation: 1715
probably not. It will understand that the first word after the define is the identifier name and the rest is the "body" of that.
Upvotes: -1