We need to use special function called type-conversion function. Type conversion function uses operator keyword and syntax is as mentioned below.

Operator type()

{}

Example

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


class Time
{
	private:
	int minutes;
	int hours;
	public:
	Time()
	{

	}
	Time (int x)
	{
		hours=x/60;
		minutes=x%60;
	}
	void display()
	{
		codut<<"Hours = "<<hours<<endl;
		cout<<"Minutes = "<<minutes<<endl;
	}

};


int main()
{

	Time t1;
	t1=72;
	t1.display();

}
Type Conversion in CPP – Conversion from Class types to basic type

Leave a Reply

Your email address will not be published. Required fields are marked *