Example generates a Name followed by "::" must be a class or namespace name

I had troubles getting an rtos program running. So I created a new program in the online compiler using the wizard. Then imported the demo program from the documentation.
It gives me a similar error as my own code.

Steps I took: first let the wizard create a new program:

Screenshot 2020-04-29 at 16.04.43

After a succesfull compilation I then replaced the contents of main.cpp with the code from
Running this example: ThisThread - APIs | Mbed OS 5 Documentation

Compiler now generates the following error:
Error: Name followed by “::” must be a class or namespace name in “main.cpp”, Line: 11, Col: 14

 #include "mbed.h"
#include "rtos.h"

Thread thread;
DigitalOut led1(LED1);

#define STOP_FLAG 1

// Blink function toggles the LED in a long running loop
void blink(DigitalOut *led) {
    while (!ThisThread::flags_wait_any_for(STOP_FLAG, 1000)) {
        *led = !*led;
    }
}

// Spawns a thread to run blink for 5 seconds
int main() {
    thread.start(callback(blink, &led1));
    ThisThread::sleep_for(5000);
    thread.flags_set(STOP_FLAG);
    thread.join();
}

Hi again,

my TIP is you again use old MbedOS5 library from that old project. Try to click on MbedOS gear icon and chose Update.
ThisThread.h was added later, I think.

  • When you want to try any example, as first check how old the example is and when was its last update.
  • Then import it and compile it in the state and with a version of Mbed in which the code was build or updated.
  • After you have verified the example is working then try to update Mbed library to latest and check if is still working.
  • When it works - now you can try to add some new feature from latest version of MbedOS and make a magic.
  • When not working - you need to find some another newer example or spend a time to solve the problem.

BR, Jan

Hello Jan, I understand your comment.
If you use an example or demo program, all libraries should have the version corresponding to that example, and requirements should be checked.

But in this case, I started with a new program generated by the online compiler. I understood the current mbedos version is 5.15. The documentation I use is also 5.15, and the code is from this demo.

Do I understand correctly, the mbed version I get when using the new program wizard in the online compiler is different than current?

Ok, sorry. I saw your project name, which is same as an old example.
For some reason the online compiler won’t import that template and get stuck instead but another projects are OK…

So the Update check box in the import control window is not working probably or it works differently. The Mbed Os library is not updated even though the check box is selected.

For the import I recommend to use the button Import into Mbed IDE from Api’s documentation page and then the Mbed library update manualy.

BR, Jan

1 Like

Thats working, thanks!