vendredi 2 février 2018

lambda function in C++ 11 not working inside class

I was trying to create a lambda function inside a c++ class, but it is giving compilation error. Code looks like:

class Test {

  public:
    struct V {
            int a;
    };

    priority_queue<V, vector<V>, function<bool(V&, V&)>>
            max_heap([](V& a, V& b) { return true; } );

};

The compilation error I am getting is:

test.cpp:32:22: error: expected identifier before '[' token
             max_heap([](V& a, V& b) { return true; } );
                      ^
test.cpp:32:35: error: creating array of functions
             max_heap([](V& a, V& b) { return true; } );
                                   ^
test.cpp:32:37: error: expected ')' before '{' token
             max_heap([](V& a, V& b) { return true; } );
                                     ^
test.cpp:32:54: error: expected unqualified-id before ')' token
             max_heap([](V& a, V& b) { return true; } );

Any explanation?

Aucun commentaire:

Enregistrer un commentaire