【发布时间】:2018-07-13 14:03:05
【问题描述】:
我试图在 c++ 类中创建一个 lambda 函数,但它给出了编译错误。代码如下:
class Test {
public:
struct V {
int a;
};
priority_queue<V, vector<V>, function<bool(V&, V&)>>
max_heap([](V& a, V& b) { return true; } );
};
我得到的编译错误是:
test.cpp:32:22: error: expected identifier before '[' token
max_heap([](V& a, V& b) { return true; } );
^
test.cpp:32:35: error: creating array of functions
max_heap([](V& a, V& b) { return true; } );
^
test.cpp:32:37: error: expected ')' before '{' token
max_heap([](V& a, V& b) { return true; } );
^
test.cpp:32:54: error: expected unqualified-id before ')' token
max_heap([](V& a, V& b) { return true; } );
有什么解释吗?
【问题讨论】:
标签: c++ c++11 lambda most-vexing-parse