Can someone please explain to me what classes do, and when to use them. I very new to C++, and I'm a little confused on what they do.
Thanks,
Kenneth Devorak
Printable View
Can someone please explain to me what classes do, and when to use them. I very new to C++, and I'm a little confused on what they do.
Thanks,
Kenneth Devorak
Classess are generally groups of functions and/or VARs. Its generally up to the programmer when to use or not use them. Here is a quick simple example
I wrote this all by hand so there maybe some minor mistakes in my examplePHP Code:class CMath //Name of your class
{
public:
int total; //Public VAR in your class
CMath();
~CMath();
void Add(int Value1, int Value2);
void Subtact(int Value, int Value2);
};
CMath::CMath()
{
}
CMath::~CMath()
{
}
void CMath::Add(int Value);
{
total = total + value;
}
void CMath::Add(int Value);
{
total = total - value;
}
int Main()
{
CMath math; //When this is done CMath::CMath() is called
math.Add(1); //When this is done CMath::Add(int Value) is called
math.Subtract(5); //When this is done CMath::Add(int Value) is called
cout << math.total;//When this is done total in CMath is called
} //When this is done void CMath::~CMath() is called because the VAR is being destroyed
You should read a tutorial, I recommend TYC++:
http://newdata.box.sk/bx/c/