   i hate classes...
  i always avoided to use classes or to learn something about them but recently i read more and more tutorials which use classes. what r those classes and whats the advantage in using them? i saw they have a private and a public part so i guess part of the advantage is information hiding. but what is with the private stuff of a class... is it only visible for members of the class and the publics r like globals? also i found an ultra overloaded class inside a tutorial.. if u ever decide to write a tutorial, please dont do this in there. n00bs can only copy and paste the code but its very hard to understand what the code does.ph33r 7hi5: (WTF DOES THIS CODE?!?)class CVector3{public:// A default constructorCVector3() {}// This is our constructor that allows us to initialize our data upon creating an instanceCVector3(float X, float Y, float Z) { x = X; y = Y; z = Z;}// Here we overload the + operator so we can add vectors together CVector3 operator+(CVector3 vVector){// Return the added vectors result.return CVector3(vVector.x + x, vVector.y + y, vVector.z + z);}// Here we overload the - operator so we can subtract vectors CVector3 operator-(CVector3 vVector){// Return the subtracted vectors resultreturn CVector3(x - vVector.x, y - vVector.y, z - vVector.z);}// Here we overload the * operator so we can multiply by scalarsCVector3 operator*(float num){// Return the scaled vectorreturn CVector3(x * num, y * num, z * num);}// Here we overload the / operator so we can divide by a scalarCVector3 operator/(float num){// Return the scale vectorreturn CVector3(x / num, y / num, z / num);}float x, y, z;};and another question (this has nothing to do with classes): is sorbeit voids directplay tutorial really the only one available? i tried google but i only find the same tutorial on every site. if i ever master directplay i swear i'll write a tutorial which explains everything step by step.   
Quote:i read more and more tutorials which use classes. what r those classes and whats the advantage in using them?Classes are not helpful unless you know the basics of object oriented programming.  So you might learn about oop which will of course lead to understanding classes.   ;  i'm already reading tutorials... if u know of a good tutorial which explains oop then let me know...EDIT: ok, now i guess i know what an easy class does and how to use it... the code sample from above still makes me feel like a n00b... i think i'll read something about overloading now..   ;  The code is an implementation of a Vector class.All the methods (methods are basicly functions inside a class) are there to make the class more natural. As you can see, there's alot of operator overloading. This makes it possible to write    vector3 = vector1 + vector2;instead of for instance    vector3 = vector1.Add( vector2 );or perhaps    vector3 = AddVectors( vector1, vector2 );There's a few things of things you need to learn to fully understand the class. But to get the major idea of how it works, you only have to look up and understand operator overloading since you seem to have the basic understanding of classes.I write pure OO apps (I'm using C#) because it perfectly fits my way of thinking. I like structuring things up, and OOP are created for this! It takes a while to move from function oriented thinking to object oriented thinking, but I have never ever heard of anyone that regretted they learned OOP.   ;  classes are nothing more than a tool to allow a you to create user-defined types like built-in types such as integer. A type is a concreate representation of a concept which you find in the problem domain. A program that provides types that closely match the concepts of the application tends to be easier to understand and easier to modify than a program that does not. A well-chosen set of user-defined types makes a program more concise.The code you have posted is a user-defined type that represents a mathematical entity, a 3d vector with the standard mathematical operations you can preform on them (thou not very well written).Now think about it, if your problem domain has concepts of vectors, wouldn't it seem more natural to work with vector types than the built-in ones provided?   ;  It may be enough for you to go to your local bookstore and take a look at section 2 of The C++ Programming Language. In there, Stroustrup goes through the steps of defining a type, from its beginning as a set of functions, all the way to a class. That way, you can see how to get from where you are to using classes, and what benefits the move will yield.   ;  thx for the reply :) i think i understand classes now enough to use them... routine will come by trying.yes, i think operator overloading is what i need to learn... but i guess i wont like it. it only makes the code unpredictable... normally i look at something and i see cvector3 for example then i assume every cvector3 thing in the code behaves in the same way... this may save a lot of writing but it also makes the code ununderstandable (is this word correct?). maybe it will look different after i read 98324792387 tutorials about overloading.EDIT: wow, that was easy... i think i understand the cvector3 code now...[Edited by - BiGF00T on July 18, 2004 9:10:57 AM]