Tuesday 24 February 2015

Defining Member Functions Outside of The Class in C++

/*
Defining Member Functions Outside of The Class
==============================================

returntype classname::functionname(arg1,....,)
{
}

*/

#include<iostream.h>
#include<conio.h>

class Rectangle
{
private:
int width,height;
public:
void Create(int,int);
void Display();
};
void Rectangle::Create(int w,int h) /* :: - Scope Resolution Operator */
{
width=w;
height=h;
}
void Rectangle::Display()
{
cout<<"\n Width :"<<width;
cout<<"\n Height :"<<height;
}
void main()
{
Rectangle r1,r2;
r1.Create(100,100);
r1.Display();
r2.Create(200,200);
r2.Display();
}

No comments:

Post a Comment