Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Const methods in C++

#include<iostream>
using namespace std;
class date
{
    private:
   int mon;
public:
   int a,b,c;
   date( int mn, int dy, int yr )
   {
       
       a=mn;
       b=dy;
       c=yr;
   }
   int getmonth() const;     
   void setMonth( int mn );   

    void getdate() const
{
    cout<<"\n";
    cout<<a;
    cout<<":";
    cout<<b;
    cout<<":";
    cout<<c;
}};

int date::getmonth() const
{
   return mon;        
}
void date::setMonth( int mn ) 
{
   mon = mn;          
}
int main()
{
   date d1( 3, 1, 2012 );
    const date d2( 2, 23, 1992 );
    d1.getdate();
      d1.setMonth( 4 );  
    cout<<"\nAfter changing month:";
    cout<<d1.getmonth();// Okay
           d2.getdate();
   
}