不知道如何更好地描述它.这是代码.这无法在gcc 4.9.2(Debian 8.5)上进行编译,我认为它很难在以前的版本中编译.只有当我在lambda设置中访问后来声明的结构的成员作为默认参数时,问题似乎才会发生.其他显示的案例工作.
// Test program
class C1
{
private:
// Forward-declared
struct S_Private;
S_Private* d_;
public:
void func();
};
struct C1::S_Private
{
int a;
};
void C1::func()
{
// This will work
int test = d_->a;
// Accessing the d_->a as a default argument in lambda setup
// will NOT work:
// error: invalid use of non-static data member ‘C1::d_’
auto some_lambda = [&](int arg = d_->a)
{
// This will also work
int test2 = d_->a;
};
} …Run Code Online (Sandbox Code Playgroud)