Write a program to use unary operator overloading


 

/* Write a program to use unary operator overloading*/

#include<iostream.h>

#include<conio.h>

class score

{

int val;

public:

score()

{

val=0;

}

void operator++()

{

val=val+1;

}

int show()

{

return(val);

}};

void main()

{

clrscr();

score s1,s2;

cout<<“value of s1=”<<s1.show()<<endl;

cout<<“value of s2=”<<s2.show()<<endl;

++s1;

++s1;

++s2;

cout<<“value of s1=”<<s1.show()<<endl;

cout<<“value of s2=”<<s2.show();

getch();

}

/*output:

value of s1=0

value of s2=0

value of s1=2

value of s2=1*/

Related Posts

Comments are closed.