View Full Version : simple question on Class-Members
mickey
4th February 2006, 13:28
Hi, I have a question:
class DOOR {
public:
........
draw();
}
class build {
public:
........
std::vector<DOOR> door;
QImage imm;
};
I need to use variable imm within member draw(). How can I do?
Thanks
jacek
4th February 2006, 14:10
What calls that DOOR::draw() method? Maybe you invoke it only from build class?
mickey
4th February 2006, 16:05
void DOOR::draw() {
imm="hello\n";
}
I'd like use imm in ::draw () and I'd like can use "only" imm and not other variables of Build class.....
jacek
4th February 2006, 16:59
I'd like use imm in ::draw () and I'd like can use "only" imm and not other variables of Build class.....
But where do you intend to use thet DOOR::draw() method?
mickey
4th February 2006, 18:30
now I don't know.
I'd like use imm within Door:draw() and compile it.
Thanks.
jacek
4th February 2006, 18:48
now I don't know.
So maybe you should redesign your classes?
For example like this:
void DOOR::draw( const QImage& img )
{
// ...
}
void build::draw()
{
// ...
for( std::vector<DOOR>::iterator it = door.begin(); it != door.end(); ++it ) {
it->draw( imm );
}
// ...
}
Other possibility is that each of DOOR instances would hold a pointer or reference to a build instance:
void DOOR::draw()
{
// ...
QImage img( _build->image() );
// ...
}
const QImage& build::image() const
{
return _imm;
}
Everything depends on the way you want to use those two classes and on things what they represent.
mickey
4th February 2006, 23:33
OK thanks. But why do you use underscore symbol?
jacek
4th February 2006, 23:37
why do you use underscore symbol?
In this case is just a habit.
In my code I add underscore to member variables to distinguish them from parameters.
Powered by vBulletin® Version 4.2.5 Copyright © 2023 vBulletin Solutions Inc. All rights reserved.