Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overloaded static member function call inside lambda body doesn't compile

So basically here is the simplified version of my code that doesn't compile:

class MyClass
{
    static void foo(X)
    {
        //do something
    }
    
    static void foo(Y)
    {
        //do something
    }
    
    static void bar()
    {
        std::for_each(collection->begin(), collection->end(),
          [&](X& elem)
        {
          foo(elem); //this call generates the error
        });
    }   
};

Compiler: MSVC 2010 with SP1 installed The error message it generates is: error C3861: 'foo': identifier not found

The error doesn't occur if I rename either foo() function, or if I call it outside the lambda.

Update:

I managed to solve this by explicitly qualifying foo(). The interesting part is that ::MyClass::foo(elem) works but MyClass::foo(elem) does not.

like image 875
Unichron Avatar asked Feb 01 '26 21:02

Unichron


1 Answers

Try to explicitly qualify foo:

MyClass::foo(elem);

(which might be a required work-around for a MSVC10 bug, GCC accepts your code without qualification)

like image 161
Daniel Frey Avatar answered Feb 04 '26 10:02

Daniel Frey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!