C++ - What does "Incomplete type not allowed" error mean, and how can I fix it?

10,409

C++ - What does “Incomplete type not allowed” error mean

Incomplete type means that there is no definition for the type SDL_Window.

The error means that the type is incomplete, and that an incomplete type wasn't allowed in that context. In this particular case: an incomplete type cannot be used as a base class.

what I should do to stop it from happening?

Do not attempt to use SDL_Window as a base class - it is not intended to be used in that way.

SDL_Window is intended to be used as an opaque pointer. Some SDL functions may return you a SDL_Window*. You can store it, and send it as an argument to other SDL functions. That is all it is used for.

Share:
10,409

Related videos on Youtube

tobahhh
Author by

tobahhh

Updated on June 04, 2022

Comments

  • tobahhh
    tobahhh 7 months

    Although I've seen many questions referring to the "Incomplete type not allowed" error in C++, I still cannot figure out what the compiler is trying to tell me when it screams at me like this. I've been able to piece together that it has something to do with #include-ing header files, but I am clueless as to what an "incomplete type" is and why it is "not allowed". I got the error when trying to inherit from SDL_Window as such:

    #pragma once
    #include "SDL.h"
    class Window : public SDL_Window
    {
    public:
      Window();
      ~Window();
    };
    

    Could someone please explain to me what the error means, how to (generally) fix it, and, in my case, what I should do to stop it from happening?

    • George
      George almost 5 years
      #include <SDL.h> -> #include "SDL.h"
    • Sam Varshavchik
      Sam Varshavchik almost 5 years
      Perhaps you should try showing the full, complete error message, instead of merely paraphrasing what it says. And providing a minimal reproducible example will not hurt, either.
    • Miles Budnek
      Miles Budnek almost 5 years
      @George SDL_Window is incomplete on purpose. It's definition is not visible to consumers of the library, and it can only be interacted with by passing/receiving pointers to it to/from SDL functions. This is a common technique used by many C libraries.
    • Amadeus
      Amadeus almost 5 years
      Because, probably, only de declaration of SDL_Window is done in header files and the definition is done elsewhere, where you can not access.
  • tobahhh
    tobahhh almost 5 years
    Ok, thank you. I am used to Java in which almost every program has a class that extends JFrame. However, I suppose that type of syntax isn't do-able in C++.
  • Jeremy Friesner
    Jeremy Friesner almost 5 years
    That type of syntax is doable in C++ (for example in Qt you can subclass QFrame); it's SDL that has made the design-decision not to allow it for their API.

Related