Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. "nested name specifier" error
Forum Update on Monday, May 27th 2025

"nested name specifier" error

Scheduled Pinned Locked Moved Solved C++ Gurus
9 Posts 5 Posters 7.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mzimmers
    wrote on 27 Mar 2019, 14:27 last edited by
    #1

    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...

    J 1 Reply Last reply 27 Mar 2019, 14:33
    0
    • M mzimmers
      27 Mar 2019, 14:27

      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...

      J Offline
      J Offline
      JonB
      wrote on 27 Mar 2019, 14:33 last edited by JonB
      #2

      @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?

      1 Reply Last reply
      1
      • M Offline
        M Offline
        mzimmers
        wrote on 27 Mar 2019, 14:45 last edited by
        #3

        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.

        K 1 Reply Last reply 27 Mar 2019, 15:32
        0
        • M mzimmers
          27 Mar 2019, 14:45

          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.

          K Offline
          K Offline
          KroMignon
          wrote on 27 Mar 2019, 15:32 last edited by
          #4

          @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?

          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

          1 Reply Last reply
          2
          • M Offline
            M Offline
            mzimmers
            wrote on 27 Mar 2019, 15:42 last edited by
            #5

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

            K K 2 Replies Last reply 27 Mar 2019, 15:48
            0
            • M mzimmers
              27 Mar 2019, 15:42

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

              K Offline
              K Offline
              KroMignon
              wrote on 27 Mar 2019, 15:48 last edited by
              #6

              @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.

              It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

              1 Reply Last reply
              0
              • M mzimmers
                27 Mar 2019, 15:42

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

                K Offline
                K Offline
                kshegunov
                Moderators
                wrote on 27 Mar 2019, 16:49 last edited by
                #7

                @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.

                Read and abide by the Qt Code of Conduct

                1 Reply Last reply
                6
                • M Offline
                  M Offline
                  mzimmers
                  wrote on 27 Mar 2019, 18:56 last edited by
                  #8

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

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    Raj Mahamud
                    Banned
                    wrote on 1 Jul 2022, 08:33 last edited by
                    #9
                    This post is deleted!
                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved