我希望在 C++20 中执行以下操作:
template <class... Ts>
struct overloaded : Ts... {
using Ts::operator( )...;
};
// Updated to work with C++17
#if (_cplusplus != 202002L) // check for C++17 or C++20
// Deduction guide, google `CTAD for aggregates` for more info
template <typename... Ts>
overloaded(Ts...) -> overloaded<Ts...>; // not needed before C++20
#endif
template <typename T, long int C = 0>
void emit(T const& data) {
auto emit = overloaded {
[&](const auto& value) {
mOs << value;
},
[&](const …Run Code Online (Sandbox Code Playgroud) 下面的代码eval在IMO应该调用NotGate版本时调用基类。它在R3调用中正确运行,但在R4调用中无效。
在typeid调用时添加了许多调用,以标识实际的“门”,并出于某种原因查找门的类型NotGate在初始化期间更改为存储为抽象门的变量operator!。operator*在我的完整代码中,或其他类似运算符不会发生这种情况。
#include <iostream>
using namespace std;
//---------------------------------------------------------------------------------------------------------------------
struct LGAbs {
enum NodeState {
Failure, Success, Running
};
LGAbs() {
}
virtual ~LGAbs() {
}
virtual NodeState eval();
};
//---------------------------------------------------------------------
LGAbs::NodeState LGAbs::eval() {
return LGAbs::Failure;
}
//----------------------------------------------------------------------
struct TrueGate : public LGAbs {
TrueGate() {
}
virtual LGAbs::NodeState eval() override {
return Success;
}
};
//----------------------------------------------------------------------
struct NotGate : public LGAbs {
NotGate(LGAbs& g) …Run Code Online (Sandbox Code Playgroud)