我试图在 lambda 中调用成员函数的基类实现。
clang++接受和gcc拒绝的以下代码是否符合标准?
#include <iostream>
class Base
{
protected:
void fn() { }
};
class Derived
: public Base
{
public:
void fn()
{
[&]() {
Base::fn(); /// compilation error here
}();
}
};
int main()
{
Derived d;
d.fn();
}
错误信息:
test.cpp: In lambda function:
test.cpp:6:10: error: void Base::fn() is protected
void fn() { }
^
test.cpp:16:22: error: within this context
Base::fn();
^
编译器版本:
gcc 版本 4.8.1 (Ubuntu/Linaro 4.8.1-10ubuntu8)
Ubuntu clang version 3.3-5ubuntu4 (branches/release_33) (based on LLVM 3.3)