| Visible to | public | protected | private |
| User | Yes | No | No |
| Derived class (Subclass) | Yes | Yes | No |
| Member functions and friends | Yes | Yes | Yes |
|
Example
class Class_Name {Example
private:
//
List of class attributes (variables, types, constants and so on) that
are intended to to be hidden
for reference from outside the class.
// List of prototypes for each member function intended to be hidden from outside of the class. ... protected:
//
List of class attributes (variables, types, constants and so on) that
may be accessed
by name from derived class but hidden from
outside the
class.
// List of prototypes for each member function may be accessed by name from derived class but hidden from outside the class. ... Example
public:
}; // Note that a class
definition has to end with a ; (semicolon)// List of class attributes (variables,
types, constants and so on) that
may be accessed
by name from outside the class.
// List of prototypes for each member functioon that may be accessed from outside the class. ... |
|
Example
Class_Name() {alloc_size = 256; // Set default values for variables in class ... }; //Note the additional ; (semicolon) here |
|
Example
Class_Name(
Param_1, Param_2 ) :
alloc_size( 256
), width( Param_1 ), Length( Param_2 ) {
... |
|
Example
Class_Name( Param_1, Param_2 = 10 ) :
alloc_size( Param_1
), items( Param_2 ) {
... |
|
Example
~Class_Name() {// Delete variables, clean up and return memory to system ... } |
|
Example
return_type method_name( Params ); // Comment |
|
Example
friend return_type member_function_name(
Params ); // Comment |
|
Example
return_type operator = ( Params ); // Comment |
|
Example
return_type Class_Name
:: member_function_name(
Params ) { //
Function body.
}... |
|
Example
return_type member_function__name(
Params ) { //
Function body.
}... |
|
Example
return_type Class_Name
:: operator = ( Params ) {//
Function body.
}... |
|
Example
return_type Class_Name
:: member_function_name(
const Param
) const {//
Function body.
}... |
|
Example
#include "header_file.hpp" // Include the header file just as usual |
|
Example
Class_Name Name_of_Object( Params ); |
|
Example
Class_Name MyFirstObj; |
|
Example
Class_Name MySecondObj( Params ); |
|
Example
Name_of_Object.member_function( Params ); |
| int value = MySecondObj.toInt(); |
|
Example
return_type member_function(
Params ) {//
Function body.
} AnotherMemberFunction( Other_Params ); // ... |
|
Example
MyFirstObj.upper();Example
MyFirstObj.split( 120 );Example
int i
= MyFirstObj.boyerMooreSearch( "Needle in Haystack" ); |
|
Example
Example
Example
int
i = MySecondObj.upper().split( 120 ).boyerMooreSearch( "Needle in Haystack" ); |
| class
SubClass_Name
: private Parent_Class { //
Class definitions etc.
};... |
| Vehicle | ||||||||||||||||||||||
| Car | Truck | |||||||||||||||||||||
| Cabriolet | Sedan | SUV | Hatchback | Station Wagon | Freight Truck | Lorry | etc. | |||||||||||||||