More in a stucture: operations

More in a stucture: operations



struct box

{
  
    double dLength,dWidth,dHeight;

    double dVolume;
  
    double get_vol()

       {
         return dLength * dWidth * dHeight;

       }  
}            14.cpp   141.cpp





Class  

class box

{
   double dLength,dWidth,dHeight;

   double dVolume;

public: 
  
   double vol(){return dLength

 dWidth * dHeight;}

  
}   15.cpp





Public vs. private   

Public functions and variables are accessible from anywhere the object is visible
Private functions and variable are only accessible from the members of the same class and friend
Protected
 
 class
  class box

{
   double dLength,dWidth,dHeight;

   double dVolume;

public:   

   double vol() ;
}
dbouble box::vol()

{
return dLength * dWidth * dHeight;} 
 
}  16.cpp







Constructors
 
A special member function

 with the same name of the 
 
class
 
No return type (not void)

Executed when an instance
 
 of
 
 the class is the created
 
17.cpp
  



Deconstructors 
 

 
A special member function 
 
with no parameters
 
Executed when the class is
 
 destroyed 
 
18.cpp
 
 
 
 
 
 
 
 
 

structure operations
structure operations





Post a Comment

0 Comments