gpt4 book ai didi

c++ - Visual Studio 中的嵌套 lambda

转载 作者:搜寻专家 更新时间:2023-10-31 00:40:25 26 4
gpt4 key购买 nike

我正在尝试在 Visual Studio 2012 中保存嵌套的 lambda 函数。

class Wrap
{
public:
typedef function<void(Wrap*)> Method;
Method method;
std::map<string, Wrap> methods;
};

Wrap x;
x.method = [](Wrap *arg) {
Wrap::Method t = [](Wrap*) {};
arg->methods["child"].method = t;
};

产生这个错误:

error C2678: binary '<' : no operator found which takes a left-hand operand of type const std::string (or there is no acceptable conversion)

我无法理解这个错误。

我已经在 g++ 和 clang 中对此进行了测试。他们可以编译它。 http://liveworkspace.org/code/4kVlUY$72

我如何使 Visual Studio 对其进行编译?任何解决方法?

最佳答案

问题与您的预期完全无关:

#include <string>

解决了。似乎比较运算符需要 <string>被显式包含,而如果您仅包含 <map> 则定义了类本身.

关于c++ - Visual Studio 中的嵌套 lambda,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14789215/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com