Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream.h>
- #include<conio.h>
- class gram; //source class
- class kilo
- {
- float x;
- public:
- kilo()
- { x=0; }
- kilo(float y)
- { x=y; }
- void show()
- { cout<<"Kilo : "<<x<<endl; }
- };
- class gram
- {
- float a;
- public:
- gram()
- { a=0; }
- gram(float b)
- { a=b; }
- void show()
- { cout<<"Gram : "<<a<<endl; }
- operator kilo() //cast operator in source class
- {
- float z;
- z=(a/1000);
- return(z);
- }
- };
- void main()
- {
- clrscr();
- kilo k;
- gram g(5750);
- g.show();
- k=g; //call casting operator
- k.show();
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement