C + + list initialization

Source: Internet
Author: User

In c++11, use curly braces to initialize variables for full application, or you can use curly braces to assign values to variables. An important feature of this initialization when used with built-in type variables is that the compiler will make an error if a list is initialized and the initial value is at risk of losing information.

int _tmain (int argc, _tchar* argv[]) {long double ld = 3.1415926536;int a{ld};int b = {ld};int c (LD); int d = Ld;return 0;}
Compiling will get the following error:

(one): Error C2397: Conversion from "long double" to "int" requires narrowing conversion (one): Warning C4244: "Initialization": Converting from "long double" to "int", possibly Losing data (): Error C2397  : Conversion from "long double" to "int" requires a narrowing conversion: Warning C4244: "Initialize": Convert from "long double" to "int", possibly missing data: Warning C4244: "Initialize": from "long" Double "Convert to int", possibly missing data: Warning C4244: "Initialize": Convert from "long double" to "int", possibly losing data
You can see that the compiler rejected the initialization request for A and B.


C + + list initialization

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.