![]() |
| | #1 |
| Registered User Join Date: Jul 2005
Posts: 32
| need help wiht using classes...namespaces... I knew some c++ but never really gain experience and haven't practice in a while since I been working on a website. I would like someone to explain to me what classes are used for. I did read what classes are on here bu still confused. I am guessing class are ways to organize code. Like for example I make a class house. this would mean any function in class house would be all functions and code for a house. like door () would be open close lock ect. am I somewhat right that class is like organizing code so if I were making a computer game I can have the house models and code to be under a house class?? I would like also someone to explain me about namespaces. explain to me by just giving a example that would show a picture of what it's uses are for. |
| hockey97 is offline | |
| | #2 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| You are pretty correct about classes. They are used in order to "create" an object "of" something, like a house, a door, a car, a washmachine, etc. They are designed in such a way as to mimick reality. They have a public interface (like your car has a wheel, and pedestals), and takes care of its own ticking (ie, the internal details of what makes the car run is handled by the class). They're also great for code reuse. Namespaces are, at least to me, a way to organize data. Think of it as storage boxes. Each box is named. Then you put stuff into those boxes. Then to access that stuff, you either tell the compiler to look inside the boxes or you explicitly tell the compiler what box it should look inside.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #3 |
| Registered User Join Date: Jul 2005
Posts: 32
| ok I am not sure if I got confused with name spaces with classes. so namespaces is like a storage area like I can say namespace house this will allow me to grab the class house if saved in that namespace. SO are classes like functions??? but basicly a tree of functions??? I mean what I thought that for example the house class. The house class would just be a name of a class which this class should have all code functions and vars ect everything related to a house. I thought of it more like a tree of functions but an arganized way of putting functions together in one place. so when you need to call the function you just use a pointer to that class and that function. the class house would hold all the code for the house it's just a way of grouping all the functions into a group and you use that group as a reference when you need to run the functions. that is what I thought. I am not sure if classes are really like a big function. it's kinda confusing for me but I am still trying to learn. |
| hockey97 is offline | |
| | #4 | |
| The larch Join Date: May 2006
Posts: 3,086
| Namespaces are a way to decorate names, so that you can avoid issues with name collisions. (Alternatively you might uses prefixes to names, but namespaces have other advantages over that.) If library A and library B both have a class called Bitmap and you need to use both libraries, then provided at least one of them uses namespaces you have a way to tell which Bitmap you mean in each instance. Namespaces aren't essential for C++ code, though. You can well declare classes and functions that are not in any namespace (just globally visible).
__________________ I might be wrong. Quote:
| |
| anon is offline | |
| | #5 | |||||||||
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| Quote:
Classes and namespaces are unrelated. Think of that postbox example. Namespaces can be used for categorizing. You can stuff a lot of functions into a namespace called House so you know these functions are used for manipulating houses. Quote:
You create an instance of this blueprint which represents an object. Say a class House. When you create a House, it IS the house itself, or is meant to represent that. Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |||||||||
| Elysia is offline | |
| | #6 | |||
| Registered User Join Date: Apr 2006
Posts: 1,193
| Quote:
Quote:
But the main purpose of a class is to store state. Quote:
__________________ It is too clear and so it is hard to see. A dunce once searched for fire with a lighted lantern. Had he known what fire was, He could have cooked his rice much sooner. | |||
| King Mir is offline | |
| | #7 |
| Registered User Join Date: Jul 2005
Posts: 32
| Thanks for the replies it help me understand classes. so basically the class house will have all data and functions of the house. so like the class house could have functions and var of doors,oven,a/c. well I will go back on this site and take a look at the coding of classes some more. |
| hockey97 is offline | |
| | #8 |
| Code Goddess Join Date: Sep 2001
Posts: 9,661
| >NameSpaceName::House will give you the house object found n that namespace. >This may be different from another house object in another namespace. A good real world example of namespaces is area codes in the United States. Telephone numbers have seven digits. Two people might have the same seven digit telephone number, and the area code can then be used to disambiguate them. Sometimes the area code is assumed and you can continue to use the seven digit telephone number. You can also use area codes to organize and categorize telephone numbers all over the country.
__________________ My best code is written with the delete key. |
| Prelude is offline | |
| | #9 |
| and the hat of sweating Join Date: Aug 2007 Location: Toronto, ON
Posts: 3,122
| |
| cpjust is offline | |
| | #10 |
| Code Goddess Join Date: Sep 2001
Posts: 9,661
| >Hey, we have area codes in Canada too. We're not that small. Canada is a part of the United States and simply refuses to admit it...just like the rest of the world.
__________________ My best code is written with the delete key. |
| Prelude is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| namespaces or static classes ?? you decide | Hussain Hani | C++ Programming | 9 | 07-11-2009 11:20 AM |
| im extreamly new help | rigo305 | C++ Programming | 27 | 04-23-2004 11:22 PM |
| Exporting VC++ classes for use with VB | Helix | Windows Programming | 2 | 12-29-2003 05:38 PM |
| Prime Number Generator... Help !?!! | Halo | C++ Programming | 9 | 10-20-2003 07:26 PM |
| include question | Wanted420 | C++ Programming | 8 | 10-17-2003 03:49 AM |