"nested name specifier" error



  • Hi all -

    I'm using Creator on a project. (I can't build with it, because I don't have a cross compiler, but it's still the best editor and code browser I know of.) I'm getting some errors that I don't fully understand.

    General-purpose header file:

    extern "C"
    {
        class Worker;
    }
    
    struct Tasks
    {
        EventGroupHandle_t tasksInitEventGroup
        Worker *worker;
        ...
    }
    

    Worker object:

    #include "structs.h"
    #include "worker.h"
    using namespace std;
    
    extern "C"
    {
    
    Worker::Worker()
    {
       ...
    

    I'm getting this error everywhere I reference the Worker class:

    incomplete type 'Worker' named in nested name specifier

    What might I be doing wrong?

    Thanks...



  • @mzimmers
    Bearing in mind that I'm not a C++ expert...

    extern "C"
    {
    Worker::Worker()
    

    how do you expect that to work in C (no classes, no ::). Come to that:

    extern "C"
    {
        class Worker;
    }
    

    what about that class in C?

    In some shape or form I think your C++ compiler is complaining when it meets Worker because it doesn't think it has met its forward declaration class Worker;, presumably because it doesn't work like that when it's inside extern "C".

    Have a read through https://stackoverflow.com/questions/52261768/extern-c-with-class-and-dll to see if I'm wrong (probably am), and whether instead you fall foul of one of the rules/restrictions there?



  • In all honesty, I don't remember why I did that. Removing them doesn't eliminate the error, though.

    I was able to eliminate the error messages by changing my kit to one I hacked up for my target, but I'm still curious as to why this wouldn't work if I were doing a conventional (non-cross) build.

    This would be a lot easier if I could just have a fake qmake for cross development. The docs refer to one, but no one seems to know what/where it is.



  • @mzimmers As @JonB says, class in not an ANSI C keyword. For me, your code don't made sense. Which C++ compiler you are using?



  • I'm using the xtensa-esp32-elf-g++.exe compiler. The program builds fine (just not from Creator).



  • @mzimmers I can't understand your code, I can't understand how this special gcc version can compile it.
    It is not standard conform, take a look at https://isocpp.org/wiki/faq/mixing-c-and-cpp

    This could help you to made your code standard conform, and so it will compile with almost all c++ compilers... not just this special version of gcc.


  • Qt Champions 2017

    @mzimmers said in "nested name specifier" error:

    The program builds fine (just not from Creator).

    Probably a compiler idiosyncrasy. It should slap you for that code. You can't request C-linkage for methods, the compiler just can't generate code for that. Use extern "C" only for the free functions you don't want decorated (decorated here refers to symbol decoration for linkage). And don't forget the implications of using C-linkage, e.g. there's no overloading for undecorated symbols, meaning that the following:

    int a() {}
    int a(int) {}
    

    is a symbol redefinition error at link time.



  • OK, thanks for the education...they're all removed and the warnings have disappeared.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.