Trouble using 'override' keyword
-
wrote on 13 May 2014, 22:04 last edited by
Hello there,
I am having trouble using the override keyword in one of my methods. Here is the code:
@
void NBhistoryInterface::addHistoryEntry(const QString & url) override
{
qDebug() << "SLOT: NBhistoryInterface::addHistoryEntry(const QString & url) override STATUS: Called";
addHistoryItem("Title", url);
qDebug() << "SLOT: NBhistoryInterface::addHistoryEntry(const QString & url) override STATUS: Completed";
}
@The program won't compile and gives this error:
"expected function body after function declarator"What am I doing wrong? Thanks!
-
Have you enabled C++11 support?
-
wrote on 14 May 2014, 04:33 last edited by
I don't believe I have. How do I do that? I thought it was enabled be default...
-
It depends on your compiler. MSVC 2013 enables it by default.
For GCC 4.8, you need to add this to your .pro file:
@
CONFIG += c++11
@ -
wrote on 14 May 2014, 05:00 last edited by
Im using whichever compiler comes in Qt Creator
-
Hi,
There's no compiler coming with Qt Creator. The only "exception" if we can say, is the MinGW package which also provides the compiler.
-
wrote on 15 May 2014, 22:07 last edited by
Sorry here is what I mean by the compiler that comes with Qt Creator: the one that runs when I press the green arrow button on the side. (I'm pretty sure thats compiling the code). Is that the MinGW package?
-
When you click the green Run button, Qt Creator simply runs whatever compiler you've installed and asked it to use.
To check the compiler you're using, click on the "Projects" button on the left.
Also, go to Tools -> Options -> Build & Run -> Kits to see all the compiler+Qt versions available on your computer.
-
wrote on 15 May 2014, 23:46 last edited by
looks like we got Clang, GCC with Qt 5.2.0
-
wrote on 16 May 2014, 04:20 last edited by
Try, as JKSH suggested, to add @CONFIG += c++11@ to .pro file.
If the error will stay the same then clang (whatever version you have) does not support this particular feature of C++ 11.If you will see a different error then probably the clang supports C++ 11.
And the error will tell you that you put override into wrong place.
It suppose to be in a "function declaration":http://en.cppreference.com/w/cpp/language/override and you have it in a definition.[EDIT] It can be specified at function definition but only if the definition is inside a class.
1/10