I just read the turtorial on classes (OOP) and i just dont get how that works or what it does could somebody please tell me in english what i need to know?
also what is that program supposed to do?
I just read the turtorial on classes (OOP) and i just dont get how that works or what it does could somebody please tell me in english what i need to know?
also what is that program supposed to do?
Stolen Quote: Buttered Toast always lands butter side down and cats always land on their feet, what happens when you strap buttered Toast to the back of a cat?
My Quote: Practice Makes Perfect Nobodys Perfect Why Practice?
C++ allows you to define your own classes, your own types. Say, for instance, you want to write a class to represent fractions. You'd write a class that has as its private data members the numerator and denominator. Then, you'd probably want to overload the insertion and extraction operators, the boolean operators, and the arithmetic operators for your fraction class. Once you do that, you can deal with your newly defined type easily.
Hmm, maybe that was a bit much.
Code:class dog { public: dog(){cout<<"A dog is being born."<<endl;} ~dog(){cout<<"All dogs go to heaven."<<endl;} void speak(){cout<<"Woof!";} string getBreed() const{return breed;} void setBreed(string b){breed=b;} private: string breed; }; int main() { dog fido; fido.setBreed("Golden Retriever"); cout<<"Fido says "; fido.speak(); cout << endl << "Fido is a " << fido.getBreed() << endl; return 0; }
FAQ
"The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.
"If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.
I guess it helps if you have a good grasp of structures. I think of classes/objects as structures with functions:
You can have a structure with variables like Doug.Height and Doug.Age or Zerg.Height and Zerg.Age. If you have a class called Person and an object called Doug, you can also have a member function called Doug.IncrimentAge(), or Doug.GetHeight().
There is a lot of C++ to learn, so I'd recommend getting a book. I don't know how many "pages" there are in the tutorial, but Teach Yourself C++ in 21 Days, by Jesse Liberty is about 750 pages! A good book will have more detailed explanations, and more examples than a short tutorial.
[EDIT]
The example in the tutorial doesn't do anythng. It's an incomplete "shell" class... just an outline to get you started. Here's another tutorial.
Last edited by DougDbug; 10-20-2003 at 07:48 PM.
Where are these other tutorials located
I want to use them more often
Stolen Quote: Buttered Toast always lands butter side down and cats always land on their feet, what happens when you strap buttered Toast to the back of a cat?
My Quote: Practice Makes Perfect Nobodys Perfect Why Practice?
I think i figured out what my problem is:
In the link above they have functions such as set_values is that a real funticion or it that what they are making?
Stolen Quote: Buttered Toast always lands butter side down and cats always land on their feet, what happens when you strap buttered Toast to the back of a cat?
My Quote: Practice Makes Perfect Nobodys Perfect Why Practice?
the set_values function is a user defined function. in other words, whomever wrote the class, wrote the set_values function.Originally posted by zergdeath1
I think i figured out what my problem is:
In the link above they have functions such as set_values is that a real funticion or it that what they are making?
What? When you click-on the "another tutorial" link above it should take you to www.cplusplus.com.Where are these other tutorials located
also i keep on seeing people end cout<< "text" <<end1 what does the end1 part do the turtorials just start adding it but dont explain.
Stolen Quote: Buttered Toast always lands butter side down and cats always land on their feet, what happens when you strap buttered Toast to the back of a cat?
My Quote: Practice Makes Perfect Nobodys Perfect Why Practice?
its not end1 its endl E N D L. endl is the same as saying /n except endl is a manipulator.
C++ Rules!!!!
------------
Microsoft Visual Studio .NET Enterprise
Not only does endl add a newline to the output, but it also flushes the output - meaning it actually sends whatever text has been added to the output. The output in your case is the console, but it can also be many other things like a file.