C++ pre-processor defines conflicting

Viewed 134
#define object object() // object -> object()
#define none object     // none -> object -> object()
#define lambda (std::function<****>)[]()  // HOW?!, lambda -> (std::function<object(object, const char*)>)[]()

The problem:

#define object object() // object -> object() changes object to object().

What i want is to make :

lambda -> (std::function<object(object, const char*)>)[]().

But due to my previous macros object turns to object().So i have :

(std::function<object()(object(), const char*)>)[]()

Is there a smarter way of doing this, maybe using #ifdef or something? I never used preprocessor macros before, so maybe am doing everything wrong. It seems it doesn't matter which one I #define first.

ANSWER:: I changed the class name from object to Object

#define object Object() // object -> Object()
#define none object     // none -> object -> Object()
#define lambda (std::function<Object(Object, const char*)>)[]() 
// now pre possessor has nothing to change and everything works fine
1 Answers

Short answer: every line of what you propose is bad practice, up to and including casting lambdas to std::function – the latter being a premature pessimization and almost never necessary nor useful.

Just write C++. It’ll be clearer to everyone.

Your question is a classic XY problem: you’re proposing a solution without stating what the problem is. The problem likely has a way easier solution or is not a problem to begin with.

You’ve stated the “problem” but that’s not it: I have no idea why you need those macros for anything. So those are not your problem. Show what sort of code you want written, and how those macros would supposedly help.

Related