Hi! In object oriented programming in c++, how do we declare a class? Please include the following things in the declaration of class and also mention their definitions at the end. The access specifiers, the constructor, the destructor. Why do we use a class? What are the advantages of classes in programming?
Declaring a class in C++
Hi Pamela,
Â
Below is an example for declaration of a class and the description is given below.
Â
class class_name {
 access_spec_1:
  member1;
 access_spec_2:
  member2;
 …
} obj_names;
Â
Class_name refers to a valid identifier for this particular class. obj_names is an optional list of object names of this class. The body of a class declaration can either be data or functional declarations. An access specifier can either be private, public or protected. These are responsible for modifying the access rights for their members. All members of a class declared with keyword class have private access by default. Classes allow programs to be written using object oriented paradigms.
Â
Regards,
Anyet