C + + type conversion function __jquery

Source: Internet
Author: User
2202.cpp: Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;
Class Test
{public
:/

	*
	Use a transformation constructor to convert the data of a specified type to an object of a class with 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 that
	implements the transformation
	}
	cannot specify a function type before the function name, and the function has no parameters
	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, the compilation error here, because the class type can not assign value to the int, once we define the
	//type conversion function, it will implicitly call


	int i;
	cin>>i;
	return 0;
}

Conversion constructors enable you to convert data of a specified type to an object of the class

You can convert an object of a class to a specified type of data by using a type conversion function

The general form of a type conversion function is:

operator type name ()

{The statement that implements the transformation}

Function type cannot be specified before function name, function has no arguments

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.