Wednesday, 26 August 2015

Constructor's Example in C++


#include"counter.h"
#include<iostream>
using namespace std;
class Counter
{
private:
  unsigned int count;
public:
  Counter()
  {
       //constructor
            count=10;
   }
   void incrementCount();
   unsigned int getCount();
};

//counter.cpp
// This is the Implementation File........

#include"counter.h"
unsigned int Counter::getCount()
{
       return count;
}
void Counter::incrementCount()
{
       count++;
}




void main()
{
Counter c; //creates an object and initializes count
cout<<c.getCount()<<endl;
c.incrementCount();
cout<<c.getCount()<<endl;
}

No comments:

Post a Comment