3

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.

5
  • Hate to fuss, but what's the exact signature of each foo? Clearly not foo(X) and foo(Y) Commented Oct 5, 2013 at 13:15
  • 1
    is this real code? what's X,Y? Commented Oct 5, 2013 at 13:15
  • Do you need [&] rather than []? Commented Oct 5, 2013 at 13:25
  • 1
    Looks like a similar problem to this stackoverflow.com/questions/14388520/… Commented Oct 5, 2013 at 13:33
  • I stripped down the real code. X and Y are some types. The [&] is irrelevant, I just left it there accidentally. Commented Oct 5, 2013 at 13:52

1 Answer 1

5

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)

Sign up to request clarification or add additional context in comments.

3 Comments

Doesn't work, but the error message is changed: error C2065: '__this' : undeclared identifier error C2227: left of '->foo' must point to class/struct/union/generic type error C2232: '->MyClass::foo' : left operand has '' type, use '.'
I marked this as accepted because it got me closer to the solution, although it was only partially correct.
@user2849493 Wow, MSVC is even more broken than I thought. :) Glad it helped you to figure out the final solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.