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
Beginner seeking help for "incomplete type not allowed"
-
- Posts: 2
- Joined: September 13th, 2018, 11:28 am
Beginner seeking help for "incomplete type not allowed"
- Attachments
-
- Sunburst275 Project Cleaned.zip
- This is my crappitas soluzioni
- (16.55 KiB) Downloaded 129 times
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Beginner seeking help for "incomplete type not allowed"
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.
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.
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;
};
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
-
- Posts: 2
- Joined: September 13th, 2018, 11:28 am
Re: Beginner seeking help for "incomplete type not allowed"
First of all, thank you very much for responding!
I thought no one will help me at all, lol.
Anyways:
I #include'd all needed headers. Meaning, in my settings_window.cpp is also the. Isn't that enough? As far as I can tell, this: 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...
I thought no one will help me at all, lol.
Anyways:
I now "deleted" the ui_w and initialized the ui_w_p to a nullptr. Unfortunately it didn't work.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 #include'd all needed headers. Meaning, in my settings_window.cpp is also the
Code: Select all
#include "settings_window.h"
Code: Select all
ui_w_p(new Ui::settings_window)
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...
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Beginner seeking help for "incomplete type not allowed"
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.
// 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?
Yes, calling: new Ui::settings_window; should call the default constructor of Ui::settings_window.
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".And what does it mean "store an obj 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
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Beginner seeking help for "incomplete type not allowed"
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