Friday 19 July 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...