Friday, July 19, 2019

Strange use of [] in C++. What is happening?

First of all, this is not a dummy question about arrays or operator[] overload!


I was trying to compile Qt Creator and I've received an error in this method:


static QList getNonEditorDocumentFactories()
{
return ExtensionSystem::PluginManager::getObjects(
[](IDocumentFactory *factory) {
return !qobject_cast(factory);
});
}

The error is:


mainwindow.cpp:748: error: expected primary-expression before ‘[’ token
mainwindow.cpp:748: error: expected primary-expression before ‘]’ token
mainwindow.cpp:748: error: expected primary-expression before ‘*’ token
mainwindow.cpp:748: error: ‘factory’ was not declared in this scope

I know that I'm doing something wrong to compile Qt Creator, probably g++ version, but the question is not that.


I would like to understand this code because for me this use of [] is syntactically incorrect. Can someone please explain me what is happening here.

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...