Currently, I was a self-learning C ++ primer 5th edition. The text says:
When used with built-in type variables, this form of initialization has one Important property: the compiler will not allow us to list the initialization of built-in type variables if the initializer can lead to loss of information:
Here is a sample code:
long double ld = 3.1415926536;
int a{ld}, b = {ld};
int c(ld), d = ld;
But when I tried it myself on the C ++ shell:
long double a=3.14159265354;
int b(a);
int c{a};
std::cout<<a<<std::endl<<b<<std::endl<<c<<std::endl;
It just gives a warning -Wnarrowing, but the program completed successfully. What for?
source
share