A class is a type.
Example:
int is a class of numbers that are integer,
bool is a class of values represented by true or false etc...
These types are known as built-in types or primary types.
The structure type was added and I hope you know about that. It also is known as user type.
A structure is a class of type known as "struct".
A class is also known as a user type.
An object is an instance of a given type e.g. an instance of a given class:
Example :
int a =10; // a is an object of int type and the value stored there is 10.
When the object a is created a constructor of the "int" class is called to build an integer from the value 10 and also there is the assignment operator called to assign it to the a object.
struct employee
{
char name[64];
int salary;
}
The above statements define the structure called "employee"
struct employee emp1; // create an object named "emp1" of type "employee"
struct employee emp2; // create an object named "emp2" of type "employee"
So what is an object ?
As in the real world, an object should be born e.g. created, have a name.
As in the real world the creation of an object is a very important moment and a major improvment introduced by classes is the posibility to control the initialization of an object at the creation moment.
That is way any class must have a constructor or if you do not provide one the compiler will generate one from you but as I said , is good you TO CONTROL HOW THE OBJECT IS CREATED.
A constructor is very important in the classes that allocate memory and in this case that class must have a destructor implemented.
As in the previous answers, there are many ways to initialize an object and you can find these in any C++ book.
Keep in mind what you should have as mimimum in every class you write:
- constructor (mimimum one)
- destructor
- copy constructor
- assignment operator
-obislavu-