Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 8th, 2005, 10:50 PM   #1
clearbit
Newbie
 
clearbit's Avatar
 
Join Date: Jun 2005
Location: far..far..away
Posts: 25
Rep Power: 0 clearbit is on a distinguished road
Objects vs. Built-in types

Still learning the basics with classes.

When making an object, im not sure i understand. for example
World aWorld;

aWorld could be an object of World, right? Well, in turn this would not be a function call, but it will call the objects constructor? I'm not sure I understand why this would call a constructor, when a simple built-in type(such as int) does not, or does it?

also would this be like initializing an object of the class? Or are built-in types completely different?
clearbit is offline   Reply With Quote
Old Jul 8th, 2005, 11:14 PM   #2
EverLearning
Hobbyist Programmer
 
EverLearning's Avatar
 
Join Date: May 2005
Location: Indiana
Posts: 130
Rep Power: 4 EverLearning is on a distinguished road
Here's what google turned up, which is sort of what you ask: here
although neither g++ nor Visual Studio .NET initialize declared variable (if you print, you aren't going to get a zero).
__________________
got math? yumm...

"All men by nature desire to know" -Aristotle, Metaphysics
EverLearning is offline   Reply With Quote
Old Jul 8th, 2005, 11:27 PM   #3
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Everlearning's link appears to have the answer you want. I'll just add this: a class is a blueprint for building something, not the something itself. The blueprints for integers and such are an inbuilt part of the language. That fact does not bring an item into existence -- you still have to declare them.

The purpose of classes is to support object-oriented design. With that, you may make a blueprint and have the resulting "thing", if you ever actually build one, be as useful as any other building block. Your statement,

World aWorld;

told the compiler that you have a blueprint for a World already defined and asks the compiler to build (instantiate, declare) one of those for you.

An object is not a function, it is a thing. A carburetor is a thing; mixing fuel and air to the appropriate level of explosiveness is a function (method) of the carburetor. The carburetor has sub-objects: jets, butterfly valves, things of that ilk. Your object may have sub-objects: other things you have defined, or predefined things such as integers.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jul 9th, 2005, 4:33 PM   #4
clearbit
Newbie
 
clearbit's Avatar
 
Join Date: Jun 2005
Location: far..far..away
Posts: 25
Rep Power: 0 clearbit is on a distinguished road
solved

Quote:
Originally Posted by EverLearning
Here's what google turned up, which is sort of what you ask: here
although neither g++ nor Visual Studio .NET initialize declared variable (if you print, you aren't going to get a zero).
Thanks for the link, explination was just what i needed

Quote:
Originally Posted by DaWei
Everlearning's link appears to have the answer you want. I'll just add this: a class is a blueprint for building something, not the something itself. The blueprints for integers and such are an inbuilt part of the language. That fact does not bring an item into existence -- you still have to declare them.
Brilliantly explained. I like the blueprint description.
__________________
spaghetti code is my only friend.. :cool:
clearbit is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:43 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC