I have the following C ++ code:
#include <iostream> #include <string> int main( int argc, char* argv[] ) { const std::string s1 = "ddd"; std::string s2( std::string( s1 ) ); std::cout << s2 << std::endl; }
Result: 1 Why? When I use the -Wall flag, compiler write warning: address 'std :: string s2 (std :: string) will always evaluate to' true
But this code:
#include <iostream> #include <string> int main( int argc, char* argv[] ) { const std::string s1 = "ddd"; std::string s2( ( std::string )( s1 ) ); std::cout << s2 << std::endl; }
Result: ddd
This is a normal result.
source share