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! :p
Printable View
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! :p
oh! and typecasting too plz thank you ;)!
step 1, turn off the iPod.
step 2, read the pages, don't just look at the pictures.
step 3, don't read the next sentence until you understand the current sentence you are reading.
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:Quote:
Originally Posted by Scarvenger
The class name is the type of the variable.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;
}
It's not important until you get into advanced C++, so don't worry about it.Quote:
oh! and typecasting too plz thank you