2202.cpp: Defines the entry point of the console application. #include "stdafx.h" #include <iostream>using namespace Std;class test{public:/* The conversion constructor allows you to convert the data of a specified type into an object of a class with a type conversion function that converts an object of a class to a data type of a specified type the general form of a conversion function is: operator type name () {The statement that implements the conversion} cannot specify a function type before the function name. function has no arguments The following example function name is: operator Int*/operator int () {return m_inum;} Private:int M_inum;}; int _tmain (int argc, _tchar* argv[]) {test test;int m = test;//This can be compiled through, if there is no type conversion function, there is a compile error here, because the class type cannot assign a value to int, once we define the//Type conversion function , it implicitly calls the int I;cin>>i;return 0;}
Conversion constructors allow you to convert data of a specified type to an object of a class
Use a type conversion function to convert an object of a class to a specified type of data
The general form of a type conversion function is:
operator type name ()
{The statement implementing the transformation}
Function type cannot be specified before function name, function has no arguments
C + + type conversion functions