I searched the forums and came up with nothing (I was amazed at that fact). The tutorial didn't help me understand classes. Their example kept referring to processorspeed and it never changed anything. First they said it was equal to 0, then equal to p.
setspeed is equal to readspeed? This doesn't make sense! Can someone please explain this and maybe give a simple, more common example. Thanks in advance!
using namespace std;
class Computer // Standard way of defining the class
// This means that all of the functions below this(and any variables)
// are accessible to the rest of the program.
// NOTE: That is a colon, NOT a semicolon...
void setspeed ( int p );
// This means that all the variables under this, until a new type of
// restriction is placed, will only be accessible to other functions in the
// class. NOTE: That is a colon, NOT a semicolon...
// Do Not forget the trailing semi-colon
//Constructors can accept arguments, but this one does not
processorspeed = 0;
//Destructors do not accept arguments
void Computer::setspeed ( int p )
// To define a function outside put the name of the class
// after the return type and then two colons, and then the name
// of the function.
processorspeed = p;
// The two colons simply tell the compiler that the function is part
// of the class
// To create an 'instance' of the class, simply treat it like you would
// a structure. (An instance is simply when you create an actual object
// from the class, as opposed to having the definition of the class)
compute.setspeed ( 100 );
// To call functions in the class, you put the name of the instance,
// a period, and then the function name.
// See above note.