|
-
October 15th, 2009, 09:13 AM
#1
2 classes header file inclusion probleml !!
Dear Friends
I am finding difficulty this is a Qt error but I think the problem is C++ related.
I am getting these errors when I am including a header file (a class) whose object I want to access from some other class ..
These two classes
'meshparameterdlg.h' has the class 'MeshParameterDlg'
'controlPointsEditorDlg.h' has the class 'ControlPointsEditorDlg'
Both the classes are inherited by QDialog.
I am including 'controlPointsEditorDlg.h' in 'meshparameterdlg.h' and
'meshparameterdlg.h' in 'controlPointsEditorDlg.h' .
I want to have 'MeshParameterDlg' object as a data member of 'ControlPointsEditorDlg' and
'ControlPointsEditorDlg' object as a data member of 'MeshParameterDlg'.
when I am adding 'controlPointsEditorDlg.h' in 'meshparameterdlg.h' then there's no problem. When user presses a button from 'MeshParameterDlg' dialog then I am instantiating another dialog class that is 'ControlPointsEditorDlg' and this dialog appears and when user presses 'ok' button on 'ControlPointsEditorDlg' class then I should get some values from the QTextEdit from 'ControlPointsEditorDlg' class, so I want 'meshparameterdlg.h' to be included in 'controlPointsEditorDlg.h' so that I can put the value from the 2nd dialog to a member in the 1st dialog.
When I am adding 'meshparameterdlg.h' in 'controlPointsEditorDlg.h' I am getting these errors.
Please see below errors.
///////////////////////////////////////////////////////////////////////////////////////////////////////
In file included from src/../include/mainwindow.h:35,
from src/../include/graphicsscene.h:19,
from src/../include/graphicsview.h:19,
from src/../include/geometry.h:25,
from src/../include/checksmoothness.h:26,
from src/checksmoothness.cpp:14:
src/../include/meshparameterdlg.h:11: error: redefinition of `class MeshParameterDlg'
src/../include/meshparameterdlg.h:11: error: previous definition of `class MeshParameterDlg'
///////////////////////////////////////////////////////////////////////////////////////////////////////
But I am not doing anythin in 'meshparameterdlg.h' at line #11. But I am adding meshparameterdlg.h header in a separate class called 'controlPointsEditorDlg.h'
in both the header file i am adding
#ifndef HEADER_H
#define HEADER_H
class definition
#endif
Could you give me some solution to this problem I am fed up for the past 2 days with these.
-
October 15th, 2009, 09:22 AM
#2
Re: 2 classes header file inclusion probleml !!
 Originally Posted by sujan.dasmahapatra
I want to have 'MeshParameterDlg' object as a data member of 'ControlPointsEditorDlg' and
'ControlPointsEditorDlg' object as a data member of 'MeshParameterDlg'.
You can't do that.
You have to forward declare one of that classes and use a pointer or a reference instead of a member object.
Kurt
-
October 15th, 2009, 09:33 AM
#3
Re: 2 classes header file inclusion probleml !!
 Originally Posted by ZuK
You can't do that.
You have to forward declare one of that classes and use a pointer or a reference instead of a member object.
Kurt
IE.
in the ControlPointsEditorDlg.h file
Code:
class CMeshParameterDlg;
class CControlPointsEditorDlg : public CDialog
{
....yadda yadda
CMesgParameterDlg *m_dlg;
}
Then include MeshParameterDlg.h in the ControlPointsEditorDlg.cpp file.
-
October 15th, 2009, 09:35 AM
#4
Re: 2 classes header file inclusion probleml !!
Ask someone to put two boxes inside each other, and they'll tell you it's impossible.
And yet it seems like people are always trying to do the equivalent in code....
-
October 15th, 2009, 09:49 AM
#5
Re: 2 classes header file inclusion probleml !!
 Originally Posted by Lindley
Ask someone to put two boxes inside each other, and they'll tell you it's impossible.
unless they are quantum boxes !
-
October 15th, 2009, 10:07 AM
#6
Re: 2 classes header file inclusion probleml !!
Will C++0x support the quantum keyword?
-
October 15th, 2009, 10:35 AM
#7
Re: 2 classes header file inclusion probleml !!
uhm... just dreaming...
Code:
int main()
{
int a = 0;
quantum int* b = &a;
quantum int* b = 0;
*b = 2; // this is (|defined> + |undefined>)/sqrt(2) behaviour
}
( ok, I'll stop diverting this thread... )
-
October 15th, 2009, 11:34 AM
#8
Re: 2 classes header file inclusion probleml !!
Even if we forward decalre the class and declare a pointer for that we need to include the header file right !
When I am inclusing 2nd header class file in the 1st header class file then there's no problem but when the moment I declare the 1st header class file in the 2nd header class file these errors come.
I'll put the two header files tomorrow see if you could help me !
Thanks
-
October 15th, 2009, 12:04 PM
#9
Re: 2 classes header file inclusion probleml !!
no, you do not need to include the header file for class 1 in the header file for class 2 if class 1 is forward declared in the header for class 2 and only pointers or references to class 1 are used in the header for class 2. That is why it breaks the circular dependency.
Wakeup in the morning and kick the day in the teeth!! Or something like that.
"i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."
-
October 15th, 2009, 12:50 PM
#10
Re: 2 classes header file inclusion probleml !!
The key is that you not try to do anything *with* those pointers or references in the header file except state that they exist.
All actual operations on those pointers/references should be placed in the source file, which *can* safely include the relevant header.
-
October 16th, 2009, 12:57 AM
#11
Re: 2 classes header file inclusion probleml !!
//1st header file -- meshparameterdlg.h
////////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef MEHSPARAMETERDLG_H
#define MESHPARAMETERDLG_H
#include <QDialog>
#include "meshInputParameter.h"
#include "controlPointsEditorDlg.h" // This is not a problem
#include "controlPointsEditorNormalDistributionDlg.h"
class ControlPointsEditorDlg;
class ControlPointsEditorNormalDistributionDlg;
class MeshParameterDlg ublic QDialog
{
Q_OBJECT
public:
ControlPointsEditorNormalDistributionDlg *controlPointsNormamlDistributionDlg;
ControlPointsEditorDlg *controlPointsDlg;
bool distributionFlag;
int i;
MeshParameterDlg();
~MeshParameterDlg();
Ui: ialog ui;
private slots:
void load_gcf();
void save_gcf();
void o_mesh_radioOn();
void c_mesh_radioOn();
void surface_distribution();
void surface_distribution_new();
void normal_distribution();
void normal_distribution_new();
void tanh();
void sinh();
void use_text_editor();
void restore_default();
void ok();
private:
//////////////////////////////////////////////////////////////////////////////
QString para1, para2, para3, para4, para5, para6, para7, para8, para9, para10;
//////////////////////////////////////////////////////////////////////////////
QString meshtype;
int meshpoints_block1, meshpoints_block2;
double domain_height, first_cell_height;
int surface_distribution_noOfPoints;
double *surface_distribution_points;
int normal_distribution_noOfPoints;
double *normal_distribution_points;
QString stretch_function;
double volume_blend, dissipation_factor;
int omesh_outlet_block1, omesh_outlet_block2;
double wake_contraction;
};
#endif //MESHPARAMETERDLG_H
///////////////////////////////////////////////////////////////////////////////////////////////////////////
//2nd header file -- controlPointsEditorDlg.h
///////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef CONTROLPOINTSEDITORDLG_H
#define CONTROLPOINTSEDITORDLG_H
#include <QDialog>
#include "controlPointsEditor.h"
#include "meshparameterdlg.h" // This is the problem
class ControlPointsEditorDlg ublic QDialog
{
Q_OBJECT
public:
ControlPointsEditorDlg();
~ControlPointsEditorDlg();
Ui: ialog1 ui;
int i;
bool flag;
int noOfPoints;
double *points;
private slots:
void clear();
void ok();
};
#endif //CONTROLPOINTSEDITORDLG_H
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// errors --
///////////////////////////////////////////
In file included from src/../include/mainwindow.h:35,
from src/../include/graphicsscene.h:19,
from src/../include/graphicsview.h:19,
from src/../include/geometry.h:25,
from src/../include/checksmoothness.h:26,
from src/checksmoothness.cpp:14:
src/../include/meshparameterdlg.h:11: error: redefinition of `class MeshParameterDlg'
src/../include/meshparameterdlg.h:11: error: previous definition of `class MeshParameterDlg'
src/checksmoothness.cpp: In member function `void CheckSmoothness: k()':
src/checksmoothness.cpp:389: warning: unused variable 'n'
make: *** [obj/checksmoothness.o] Error 1
////////////////////////////////////////////////////////////////////////////////////////////////////////////
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|