PDA

View Full Version : hint on OO



mickey
6th July 2006, 10:11
HI, I have mainform class that has got a member object WIDGETGL; widgetGL show some GL objects that are members of StructureGL; there's only one instance of StructureGL (ok); I declared it as global variabile inside mainform.ui.h; in others part of app that StructureGL is request I used extern declaration...


//mainform.ui.h
StructureGL strutGL;



//WIDGETGL.cpp
extern StructureGL strutGL;
void WIDGETG::paintGL()
structGL.drawSPhere();

the question: can it be ok? Is it better declare strutGL as member of mainform class? or what? thanks...

high_flyer
6th July 2006, 16:22
In general globals in C++ are bad practice (seldom they are really needed)
Is there anything preventing you from making something like:


//define in widgetg.h: StructureGL m_structGL;
void WIDGETG::setStructure(const StructureGL &strutGL)
{
m_structGL = structGL;
}

mickey
6th July 2006, 18:15
is make strutGL member of MainForm class a bad idea? mainform must use strutGL....

high_flyer
6th July 2006, 18:19
Could you elaborate on the problem you have?
What it is you want to do, and what are the alternatives you are considering to acheive it?

mickey
6th July 2006, 18:27
mainform class need to use that structGL and widgetGL too; I wonder if an instance of structGL as member of mainform class is likely...you just said avoid global variabiles.....

high_flyer
7th July 2006, 10:52
What is the relationship between mainform and widgetGL?
Is one a member of the other?
Can one access the other?
Is there another object that sees them both?

mickey
7th July 2006, 10:55
What is the relationship between mainform and widgetGL?
Is one a member of the other?
Can one access the other?
Is there another object that sees them both?
widgetGL is member of MainForm; widgetGL can access to MainForm class and viceversa;
there isn't object that can see both them..

high_flyer
7th July 2006, 13:38
So what is the problem then?
If both classes need to access the same element, and one class is a member of the other then just make structGL member in MainForm and pass it to and from widgetGL the way I showed in the beginning.