[英]C++ pre-processor defines conflicting
#define object object() // object -> object()
#define none object // none -> object -> object()
#define lambda (std::function<****>)[]() // HOW?!, lambda -> (std::function<object(object, const char*)>)[]()
#define object object() // object -> object()
changes object
to object()
. #define object object() // object -> object()
将object
更改为object()
。
What i want is to make:我想做的是:
lambda
-> (std::function<object(object, const char*)>)[]()
. lambda
-> (std::function<object(object, const char*)>)[]()
。
But due to my previews macros object
turns to object()
.So i have:但由于我的预览宏object
转向object()
。所以我有:
(std::function<object()(object(), const char*)>)[]()
Is there a smarter way of doing this, maybe using #ifdef
or something?有没有更聪明的方法可以做到这一点,也许使用#ifdef
之类的? I never used preprocessor macros before, so maybe am doing everything wrong.我以前从未使用过预处理器宏,所以也许我做错了。 It seems it doesn't matter which one I #define
first.我首先#define
似乎并不重要。
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.简短的回答:你提出的每一行都是不好的做法,直到并包括将 lambda 转换为 std::function ——后者是过早的悲观,几乎没有必要也没有用。
Just write C++.只需写 C++。 It'll be clearer to everyone.每个人都会更清楚。
Your question is probably a classic XY problem: you're proposing a solution without stating what the problem is.您的问题可能是一个经典的 XY 问题:您提出了一个解决方案而没有说明问题是什么。 The problem likely has a way easier solution or is not a problem to begin with.该问题可能有更简单的解决方案,或者一开始就不是问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.