Mail Archives: djgpp/1997/06/13/08:43:15
>
> I have a question regarding c++. Maybe it's not a good one for this group,
> but I use DJGPP so what the hell.
> Let's say a class called object, and a global variable of that class. In
> one of my functions I say
> my_obj = Object(..something...);
> This function is called a lot of times in my program, and my question is:
> will the constructor generate a new copy of this object each time I call
> it. And if it does will the memory previously taken by my_obj be freed?
> Thank you.
>
> Andrew Deren
> aderen AT eecs DOT uic DOT edu
> http://www.geocities.com/SiliconValley/Vista/1042
> Look at the home page for three of my games.
This is a repost of my own message to make things more clear.
Here is an example:
class Object {
protected:
char some_stuff[2000];
int x, y;
public:
Object (void) {}
Object (int nx, int ny) {x = nx; y=ny;}
//the constructor is doing much more but I think it's irrelevelant.
...
};
my_obj Object;
void InitObj(int x, int y)
{
my_obj = Object(x, y);
....
}
main()
{
int x,y;
while (1==1) {
scanf("%d%d", &x, &y);
InitObj(x, y);
}
...
}
This is only an example so it might not be correct. It's only to
illustrate what I mean.
Thanks.
- Raw text -