![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jun 2005
Location: far..far..away
Posts: 25
Rep Power: 0
![]() |
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? |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: May 2005
Location: Indiana
Posts: 130
Rep Power: 4
![]() |
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). |
|
|
|
|
|
#3 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#4 | ||
|
Newbie
Join Date: Jun 2005
Location: far..far..away
Posts: 25
Rep Power: 0
![]() |
solved
Quote:
Quote:
![]()
__________________
spaghetti code is my only friend.. :cool: |
||
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|