So, I wrote something like thisAnd it printedI'm a bit confused:Is this well-defined behaviour, or is it implementation specific?
I seem to have found something that clang and gcc disagree on. Here's the code:This successfully compiles with gcc 7.4.0 but fails with clang 7.0.0 with this error message:
When I subtract a float from an integer (e.g. 1-2.0), Python does implicit type conversion (I think). But when I call what I thought was the same operation using the magic method __sub__, it suddenly does not anymore.
I have a template class like this:and a function I would like to be able to call the function and the constructor like this:
Consider the following code:I want the compiler to raise a warning when passing const char* instead of bool as a parameter to function foo.
Before I studied the explicit keyword, my teacher said: "compiler doesn't execute consecutive user defined conversion". If it is true, are there any errors in my code? Or have I misunderstood my teacher? I'm working in VS2017.
Clang 6, clang 7, and gcc 7.1, 7.2, and 7.3 all agree that the following is valid C++17 code, but is ambiguous under C++14 and C++11. MSVC 2015 and 2017 accept it as well. However, gcc-8.1 and 8.2 reject it even in c++17 mode:
I am having trouble understanding why the following copy-initialisation doesn't compile:A unique_ptr<derived> can be moved into a unique_ptr<base>, so why the second statement works and the last doesn't? Aren't non-explicit constructors considered when copy-initialising? The error from gcc-8.2.0 is
This is a weird behaviour that I cannot make sense of. In my example I am having a class Sample<T> and in an implicit conversion operator from T to Sample<T>.