Beginner seeking help for "incomplete type not allowed"

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
Sunburst275
Posts: 2
Joined: September 13th, 2018, 11:28 am

Beginner seeking help for "incomplete type not allowed"

Post by Sunburst275 » September 13th, 2018, 11:44 am

Hey there,

TL;DR: Can't call new obj of class(?) because of "incomplete type not allowed". I have no idea how to fix this. Please help me. I'll show vegana.


I've been trying to figure this out for a long time already, but it's always telling me, that the type is incomplete and thus not allowed. I asked in the Discord- Server but I didn't get a very broad response. To be honest I have no idea why it is the way it is and I tried so much but failed. Now I seek help in the Forum of the famous Chili and hope that you can help me.

And please don't mind the bad coding style e.g. in the declaration of the Main Class. I'm new to OOP, coming from C. And yes, I watch Chili's tutorials.

I hope I cleaned my solution enough, wasn't sure whether that's all I need to do. If I missed something, please call me out.
Thank you so much in advance,
Sunburst
Attachments
Sunburst275 Project Cleaned.zip
This is my crappitas soluzioni
(16.55 KiB) Downloaded 129 times

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Beginner seeking help for "incomplete type not allowed"

Post by albinopapa » September 13th, 2018, 6:15 pm

Well, I don't have Latex or Qt installed, but "incomplete type not allowed" means that you are using/accessing or storing an object by value and the compiler only knows that it exists, but not it's definition.

Example: If you forward declare a type, but never #include the header, it would give such an error when you tried using it.

Code: Select all

namespace Ui {
class settings_window;
}

class settings_window : public QDialog
{
    Q_OBJECT

public:
    explicit settings_window(QWidget *parent = nullptr);
    ~settings_window();

private:
    Ui::settings_window ui_w;
    Ui::settings_window* ui_w_p = &ui_w;

};
Here's a good example. You forward declare class settings_window in the Ui namespace, then in global class settings_window, you try storing an instance of Ui::settings_window ui_w; You can't store an object by value, if the compiler doesn't have access to the class body. Either, remove the ui_w and initialize the ui_w_p to nullptr or #include the header file the Ui::settings_window is located.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Sunburst275
Posts: 2
Joined: September 13th, 2018, 11:28 am

Re: Beginner seeking help for "incomplete type not allowed"

Post by Sunburst275 » September 13th, 2018, 8:44 pm

First of all, thank you very much for responding!
I thought no one will help me at all, lol.
Anyways:
albinopapa wrote: You can't store an object by value, if the compiler doesn't have access to the class body. Either, remove the ui_w and initialize the ui_w_p to nullptr or #include the header file the Ui::settings_window is located.
I now "deleted" the ui_w and initialized the ui_w_p to a nullptr. Unfortunately it didn't work.

I #include'd all needed headers. Meaning, in my settings_window.cpp is also the

Code: Select all

#include "settings_window.h"
. Isn't that enough? As far as I can tell, this:

Code: Select all

ui_w_p(new Ui::settings_window)
calls the ctor, right? So it theoretically should work, right?

So the Ui::settings_window- header is included. Looks like the Ui- namespace is just loosely declared in no specific header, only the "main"- headers of the windows of qt.

And what does it mean "store an obj by value"?

I'm sorry but even though I've read through countless lectures and forums etc. I couldn't find answers to my questions... :(

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Beginner seeking help for "incomplete type not allowed"

Post by albinopapa » September 14th, 2018, 1:26 am

namespaces don't need to be declared or defined per se. Once you type namespace and give it a name in the global scope, it's now a name space for all headers that #include that file.

Yes, calling: new Ui::settings_window; should call the default constructor of Ui::settings_window.
And what does it mean "store an obj by value"?
Well, exactly what you were doing, it wasn't a reference and it wasn't a pointer it was the instance or Ui::settings_window. It probably doesn't hold the same semantic as when you say,"pass by value".

// Pass by value
void Func( Ui::settings_window _window )

// Pass by reference ( const reference to be precise )
void Func( const Ui::settings_window& _winref )

// Pass by address ( or pointer )
void Func( Ui::settings_window const * const _winptr )

Though, the first and last ones should be familiar to you coming from C.

I suppose what I meant by storing by value, I meant storing "an instance of".


Are you still getting the same error?
Are you trying to use in class initialization? This won't work possibly for the same reason as storing an instance of won't work.
If you have #include'd the proper headers, did you delete the forward declaration of Ui::settings_window?
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Beginner seeking help for "incomplete type not allowed"

Post by albinopapa » September 14th, 2018, 1:29 am

If you can figure out GitHub, upload your project there, and share the link to your repository. This a few advantages. One, you won't have to ZIP and reupload every time you run into an issue. Two you get version control, which means if you save and commit often, you can just go back to a previous commit and you only lose the parts of the project you most recently messed up on.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Post Reply