implicit-conversion

Why doesn't g++ -Wconversion warn about conversion of double to long int when double is constant?

怎甘沉沦 提交于 2021-02-09 07:15:12
问题 If I pass a double to a function requiring long, g++ warns of conversion problem, but if I pass a const double to a function requiring long, g++ is happy. The warning is the following: warning: conversion to ‘long int’ from ‘double’ may alter its value [-Wconversion] I would like g++ to give me a warning whether I pass a double or a const double. How would I do so? I have makefile and some code you can run. I like to turn on as many warnings as I can, but perhaps one is implicitly shutting

Why doesn't g++ -Wconversion warn about conversion of double to long int when double is constant?

☆樱花仙子☆ 提交于 2021-02-09 07:12:27
问题 If I pass a double to a function requiring long, g++ warns of conversion problem, but if I pass a const double to a function requiring long, g++ is happy. The warning is the following: warning: conversion to ‘long int’ from ‘double’ may alter its value [-Wconversion] I would like g++ to give me a warning whether I pass a double or a const double. How would I do so? I have makefile and some code you can run. I like to turn on as many warnings as I can, but perhaps one is implicitly shutting

Why doesn't g++ -Wconversion warn about conversion of double to long int when double is constant?

老子叫甜甜 提交于 2021-02-09 07:11:13
问题 If I pass a double to a function requiring long, g++ warns of conversion problem, but if I pass a const double to a function requiring long, g++ is happy. The warning is the following: warning: conversion to ‘long int’ from ‘double’ may alter its value [-Wconversion] I would like g++ to give me a warning whether I pass a double or a const double. How would I do so? I have makefile and some code you can run. I like to turn on as many warnings as I can, but perhaps one is implicitly shutting

Why doesn't g++ -Wconversion warn about conversion of double to long int when double is constant?

為{幸葍}努か 提交于 2021-02-09 07:10:17
问题 If I pass a double to a function requiring long, g++ warns of conversion problem, but if I pass a const double to a function requiring long, g++ is happy. The warning is the following: warning: conversion to ‘long int’ from ‘double’ may alter its value [-Wconversion] I would like g++ to give me a warning whether I pass a double or a const double. How would I do so? I have makefile and some code you can run. I like to turn on as many warnings as I can, but perhaps one is implicitly shutting

No warning for implicit cast of bool to floating type?

泪湿孤枕 提交于 2021-02-07 13:18:28
问题 Looks like this snippet compiles in clang without warning, even with -Weverything: double x; ... if (fabs(x > 1.0)) { ... } Am I missing something? Or do the compiler and C++ standard think that casting bool to double is something that makes sense? 回答1: This is a consequence of making bool an integral type. According to C++ standard, section 3.9.1.6 Values of type bool are either true or false (Note: There are no signed , unsigned , short , or long bool types or values. — end note) Values of

Why can't nullptr convert to int?

你离开我真会死。 提交于 2021-02-06 09:58:47
问题 Summary: nullptr converts to bool , and bool converts to int , so why doesn't nullptr convert to int ? This code is okay: void f(bool); f(nullptr); // fine, nullptr converts to bool And this is okay: bool b; int i(b); // fine, bool converts to int So why isn't this okay? void f(int); f(nullptr); // why not convert nullptr to bool, then bool to int? 回答1: Because it is exactly the main idea of nullptr . nullptr was meant to avoid this behavior: struct myclass {}; void f(myclass* a) { std::cout

Implicit conversion of a numeric in mysql

不打扰是莪最后的温柔 提交于 2021-02-04 21:51:01
问题 table struct: CREATE TABLE `test_table` ( `pk_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(30) NOT NULL, `password` varchar(128) NOT NULL, `version` bigint(20) NOT NULL, PRIMARY KEY (`pk_id`) ) ENGINE=InnoDB AUTO_INCREMENT=18446744073709551601 DEFAULT CHARSET=utf8; data: /* -- Query: SELECT * FROM test_table -- Date: 2017-09-15 16:51 */ INSERT INTO `test_table` (`pk_id`,`name`,`password`,`version`) VALUES (10545342555594296735,'testabc','testabc',5); INSERT INTO `test_table

Implicit conversion from user-defined type to primitive type in C++

时光怂恿深爱的人放手 提交于 2021-02-04 14:59:06
问题 I am able to find plenty of information about implicit conversion from, say, an int to a user defined type. i.e. if a constructor takes an int as its parameter and is not prefaced by "explicit" then implicit conversions can occur. What if I want my class to implicitly convert to an int? For example, what function needs to be added either inside or outside of SimpleClass such that the main function will compile and output "1" to the console? (see comments) #include <iostream> class SimpleClass

Implicit conversion for multiple parameters

青春壹個敷衍的年華 提交于 2021-01-29 15:07:10
问题 Is it possible to implement in Scala an implicit conversion for the group of parameters (without defining them as some class member) like implicit def triple2One (x :Int, s :String, d :Double) = x // just as an example So that I would be able to call it in the code like val x :Int = (1, "test", 2.0) 回答1: It is possible: scala> implicit def iFromISD(isd: (Int, String, Double)): Int = isd._1 iFromISD: (isd: (Int, String, Double))Int scala> val x: Int = (1, "two", 3.0) x: Int = 1 Naturally,

Why can't the compiler select the correct String.contains method when using this lambda shorthand?

牧云@^-^@ 提交于 2021-01-29 14:30:00
问题 Say I want to check if a string contains any of the letters in "cory": def hasCory(input: String): Boolean = { val myName = "cory" input.exists(myName.contains) } The compiler complains with: error: type mismatch; found : CharSequence => Boolean required: Char => Boolean Scala provides the Char -accepting method I want in StringOps: But it appears that the compiler cannot see this method unless I change the code to one of: input.exists(myName.contains(_)) input.exists(c => myName.contains(c))