Conversion Between the built-in types of C ++ and user-defined types

Source: Internet
Author: User

Conversion Between the built-in types of C ++ and user-defined types

There are two main ways to convert the two types. The first is to convert the built-in type to the User-Defined type. Here, we take the int type conversion to the class type object as an example, second, convert the class type to the int type.

The former relies on conversion constructors, and the latter relies on custom type conversion functions.

1. Conversion Constructor

Ii. type conversion Constructor

 

 

# Include

 
  
Using namespace std; // The conversion constructor has only one parameter, but sometimes the constructor of this parameter not only plays a role in type conversion but also plays a role in constructor, however, only one constructor has a similar double identity. In this case, the default copy constructor class Trans {private: int m_data; public: trans (const Trans & t) {cout <"Copy Test Obj:" <

  

   

 

Related Article

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.