April 15, 2021, 04:55:28 AM

Author Topic: Constructors and Destructors  (Read 30504 times)

0 Members and 1 Guest are viewing this topic.

Offline benthehutt

  • Global Moderator
  • Seasoned Poster
  • *****
  • Posts: 368
  • Country:
  • "Drugs? You'd better not be!" - my mom
    • Echelon9
Re:Constructors and Destructors
« Reply #15 on: April 01, 2005, 09:57:32 AM »
Yay for C++!! ;D
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.

Offline godaigo

  • Global Moderator
  • Member
  • *****
  • Posts: 205
  • Country:
  • I love YaBB SE!
Re:Constructors and Destructors
« Reply #16 on: April 01, 2005, 04:40:56 PM »
All right I'll take a stab at this stuff again. As for where the variable name is stored, I actually don't remember (and I know I have a reference that would tell me, but I don't have it handy, it's in storage) unless it's stored as part of the actual byte string of the variable value??? Not really sure though, sorry....  Oh and as to why the destructor's and constructor's work without more to them is that they all function at the compiler level and how they're declared within the class allow the compiler to recognize them and thus execute their actions. Also remember that destructors are called in the reverse order of any constructors called. Allright, I did a little research and it looks like you can declare an instance of  class in the method of another class. If you have a constructor defined for the class of the instance you are declaring it will use that, otherwise it will call the default C++ constructor which is binary 0. This happens after control passes to the constructor for the class you are currently in but before control passes to the first statement in that constructor (if that makes sense). So the instance would be set by its constructor before the constructor of the method you were declaring set it's instances. (I hope that's not too confusing). My feeling with the destructor is that the instance will be destructed at the end of main() due to the standard C++ compiler settings. However, there are some exceptions to this depending upon how you go about it. For instance, you couldn't pass data to that instance of the other class from within the constructor of the method itself because it already exists before the body of the constructor is executed. As with so many things in C++ there is a way around that, but I think that's more in-depth than I want to get on the boards, but it might be great for the teaching sight, eh Cobby! Now I will add the disclaimer that I am fairly rusty with this so if anyone else following the thread wants to tell me I'm on crack and totally wrong please due, I'm always up for learning new stuff myself! Cheers.... :)
Godaigo
All's fair in Love and Brewing.

Offline godaigo

  • Global Moderator
  • Member
  • *****
  • Posts: 205
  • Country:
  • I love YaBB SE!
Re:Constructors and Destructors
« Reply #17 on: April 01, 2005, 04:43:25 PM »
Here's a nice list of the order of Construction I found:
Local and static objects are constructed in the order in which their declarations are invoked.

Static objects are constructed only once.

All global objects are constructed before main().

Global objects are constructed in no particular order.

Members are constructed in the order in which they are declared in the class.

Destructors are invoked in the reverse order from constructors.

Hope that helps ben! Cheers....
Godaigo
All's fair in Love and Brewing.

Offline benthehutt

  • Global Moderator
  • Seasoned Poster
  • *****
  • Posts: 368
  • Country:
  • "Drugs? You'd better not be!" - my mom
    • Echelon9
Re:Constructors and Destructors
« Reply #18 on: April 05, 2005, 05:40:47 PM »
Wow, that was alot of info at once.  Thanks godaigo, you da man!

I only have one more question, and I fear you'll laugh at it cause it's kind of stupid, but here it is:

can you return anything?  For instance (this may be stupid), can you say

return cClass returnClass;

If cClass is a class with no constructor?  Cause then, in my strange little mind, it would a return zero, because it would use the default constructor 0.

I think that's way off, but could it happen??? :o
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.

Offline godaigo

  • Global Moderator
  • Member
  • *****
  • Posts: 205
  • Country:
  • I love YaBB SE!
Re:Constructors and Destructors
« Reply #19 on: April 06, 2005, 05:21:06 PM »
Hey ben, I'm glad that I'm being helpful. Like I said before, if anyone has better working knowledge of this please jump in! My basic understanding is that the constructor has no return type since it is called automatically, so if you tried to return something it would probably throw an error since there would be no memory allocated to hold the return value. I'm not positive of that though so I'm going to do some more reading and I'll let you know if I come across something else. I have a feeling and vague stirrings of memory that there is more to this than meets the eye. I'll post what I find out! Cheers....
Godaigo
All's fair in Love and Brewing.

Offline benthehutt

  • Global Moderator
  • Seasoned Poster
  • *****
  • Posts: 368
  • Country:
  • "Drugs? You'd better not be!" - my mom
    • Echelon9
Re:Constructors and Destructors
« Reply #20 on: April 06, 2005, 06:19:15 PM »
Sorry if I'm bugging you with all of these questions, but you are really helpful.  Thanks for all the help... :)
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.

Offline godaigo

  • Global Moderator
  • Member
  • *****
  • Posts: 205
  • Country:
  • I love YaBB SE!
Re:Constructors and Destructors
« Reply #21 on: April 07, 2005, 02:39:45 PM »
No problem, I have to say that although I've been on this board for a fairly long time (since before we transfered to this new format) I don't believe that I've really contributed anything (at least technically speaking), so if I'm doing that now that's awesome. So I'm actually waiting for parts (it's hard to get them in the frozen north sometimes) and my home compuker is down, but I'll see what I can come up with on your questions still. Cheers....
Godaigo
All's fair in Love and Brewing.

Offline Metgod

  • the deranged hacker
  • Administrator
  • Forum Hero
  • *****
  • Posts: 1116
  • Country:
  • Gender: Male
Re:Constructors and Destructors
« Reply #22 on: April 07, 2005, 03:57:39 PM »
You're still up there or have things there ? Damn.. I'd personally love to live in colder environment but not if it's because of what I remember you being there for (work or something I think).

When do you get everything back set up ?

"My Terminal is my Soul"

Offline godaigo

  • Global Moderator
  • Member
  • *****
  • Posts: 205
  • Country:
  • I love YaBB SE!
Re:Constructors and Destructors
« Reply #23 on: April 07, 2005, 04:57:19 PM »
Actually my compuker's power supply just fried, so I had to order a new one and I'm just waiting for it to be delivered. I had to take slow shipping because they wanted twice as much for shipping as the case itself cost. Basically I'm up here for work and most of my stuff is in storage back down south with my parents. Speaking of work I have to get going, but I'll reply some more in another post! Cheers Metty!
Godaigo
All's fair in Love and Brewing.

Offline Metgod

  • the deranged hacker
  • Administrator
  • Forum Hero
  • *****
  • Posts: 1116
  • Country:
  • Gender: Male
Re:Constructors and Destructors
« Reply #24 on: April 07, 2005, 05:56:46 PM »
Ouch...

I got a computer a couple years ago and it's been junk ever since. I couldnt get it to work. So I get a new motherboard (quite pricey for me) and then I try to install the OS and it still bails out. It then hits me how stupid I was.. that it was probably ram. So I buy new ram and it works.. what a waste of money.

Was rather pissed at myself (this happened a week or two ago)... as money doesn't come easy to me.

Hope you get your PSU back soon.
"My Terminal is my Soul"

Offline godaigo

  • Global Moderator
  • Member
  • *****
  • Posts: 205
  • Country:
  • I love YaBB SE!
Re:Constructors and Destructors
« Reply #25 on: April 07, 2005, 09:16:14 PM »
Yeah, I have to object on principle to paying $100 for shipping for a $45 power supply and case. Oh well.....
Godaigo
All's fair in Love and Brewing.

Offline wilnix

  • mv user /dev/null
  • Administrator
  • Forum Hero
  • *****
  • Posts: 690
  • Country:
  • Gender: Male
  • You're not the fastest packet in the subnet...
    • Wilnix - The NetAdmin's Resource
Re:Constructors and Destructors
« Reply #26 on: August 14, 2005, 02:37:18 AM »
BenTheHutt -

Did you get your question answered? Variable storage?


Let me know cuz I can help...

Wilnix
alt email address: wilnix@hackphreak.org

Offline benthehutt

  • Global Moderator
  • Seasoned Poster
  • *****
  • Posts: 368
  • Country:
  • "Drugs? You'd better not be!" - my mom
    • Echelon9
Re:Constructors and Destructors
« Reply #27 on: August 14, 2005, 03:46:22 PM »
Well, I still don't really understand the whole "storing pi" thing, but no one had any idea how you could do that with any variable in C++.
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.

Offline wilnix

  • mv user /dev/null
  • Administrator
  • Forum Hero
  • *****
  • Posts: 690
  • Country:
  • Gender: Male
  • You're not the fastest packet in the subnet...
    • Wilnix - The NetAdmin's Resource
Re:Constructors and Destructors
« Reply #28 on: August 15, 2005, 01:44:27 AM »
Yeah -


Read this: http://www.cs.berkeley.edu/~ejr/GSI/2000-spring/cs267/assignments/assignment1-results/flab/

Store that in memory? I don't think so...unless the word 'Cray' appears...


Thanks,

Will
alt email address: wilnix@hackphreak.org

Offline benthehutt

  • Global Moderator
  • Seasoned Poster
  • *****
  • Posts: 368
  • Country:
  • "Drugs? You'd better not be!" - my mom
    • Echelon9
Re:Constructors and Destructors
« Reply #29 on: August 15, 2005, 12:25:59 PM »
I am thoroughly convinced that no cray on the face of this earth could even do that.  For one thing, 865 gigs of RAM doesn't come close to what they would need to store the number in RAM even once.  There's gotta be some other way for them to do it.  What they were using was an algorithm, which means that they do an operation over and over and over.  Even a cray can't move around a 206 billion digit number that fast.  Assuming they had enough RAM to store the number, clearing it out of RAM to put it back in for the next computation would take more than 30 minutes (which is the total time it took).
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.