Beruflich Dokumente
Kultur Dokumente
Specifying a Class
A class is an extension of the idea of structure used in C. It is a new way of creating and implementing a user-defined data type. A class is a way to bind the data and its associated functions together. It allows the data and functions to be hidden, if necessary, from external use.
Class specification
Class Declaration: - describes the type and scope of its members. Class function definitions: - describes how the class functions are implemented.
General form of Class Declaration class class_name { Private: variable declarations; function declarations; Public: variable declarations; function declarations; };
The class declaration is similar to the struct declaration. The keyword class specifies, that what follows is an abstract data of type class_name. The body of the class is enclosed within braces {} and terminated by a semicolon(;). The class body contains the declaration of variables and functions. These variables and functions are collectively called class members: - private and public.
Syntax
Outside the class definition: Return_type class_name :: function_name (arg) { function body; }
Inside the class definition: class abc { //by default private Int x,y; //variables declaration Public: void getdata(int a, int b); //declaration void putdata(void) //definition inside the class { cout << x << \n; cout << x << \n; } };
THANKS!!!