Originally Posted by
Scarvenger
I was reading the tutorial of classes and i didnt understood anything! help me if you could explain to me i would be very happy ty!
Do you know what an array is? A rudimentary explanation of a class is that it's like an array except that you're not limited to storing one type of data in it. With an array, each element of the array has to be the same type. With a class, you can store different types of data in an object of the class. Here is an example:
Code:
#include <iostream>
#include <string>
using namespace std;
class MyClass
{
public:
string name;
int age;
double height;
};
int main()
{
int myArray[] = {1, 2, 3}; //create an array
cout<<myArray[0]<<endl;
cout<<myArray[2]<<endl;
cout<<endl;
MyClass data; //create an object of the class
data.name = "Sally";
data.age = 18;
data.height = 150;
cout<<data.name<<endl
<<data.age<<endl
<<data.height<<endl;
return 0;
}
The class name is the type of the variable.
oh! and typecasting too plz thank you
It's not important until you get into advanced C++, so don't worry about it.