我正在尝试在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)