Problem with passing object of my class as parameter to other object.
I'm working on text editor in Qt and I have a small problem. There are 2 classes MainWindow and Editor and what I'm trying to do is to pass one of the as a parameter to the other.
Here is the LINK to gist containing header files of that 2 classes.
If I compile this code it gives me two errors:
- editor.h:13: error: expected ')' before '*' token
Editor(MainWindow *parent, QString path, QString name, QString content);
- editor.h:23: error: 'MainWindow' does not name a type
Thanks for help.
MainWindow' does not name a type
hi, this sounds like you did not include "mainwindow.h"
so it knows that type?
@mrjj Hi, thanks for fast reply. Include is not the issue here, if you look at the gist I've posted link to, you'll see that I have "mainwindow.h" included in "editor.h".
You have circular includes: MainWindow includes Editor and Editor includes MainWindows. This is not going to work.
If you only use pointer to MainWindow in Editor you can remove the include and add forward declaration:
Don't forget to include MainWindow in Editor.cpp
I was going to suggest the same as @jsulm. Use forward declaration of MainWindow in your header and include the header in your CPP.
Thanks a lot guys, forward declaration solved it.
That circular dependency triggers another question: why do you need it ? Sounds like you are preparing a tight coupling between these two classes and it's something you should avoid.