delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/06/13/08:43:15

Date: Fri, 13 Jun 1997 07:44:03 -0500 (CDT)
From: Andrew Deren <aderen AT eecs DOT uic DOT edu>
To: djgpp <djgpp AT delorie DOT com>
Subject: Re: C++ question. (fwd)
Message-ID: <Pine.SUN.3.95.970613073825.25529B-100000@ernie.eecs.uic.edu>
MIME-Version: 1.0


> 
> 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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019