Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
primitive type copy constructor
#include <cassert> #include <iostream> struct MyClass { int m = 0; }; MyClass& f(MyClass& x) { x.m++; return x; } inline MyClass f(MyClass&& x) { return f(x); } int& f(int& x) { x++; return x; } inline int f(int&& x) { return f(x); } int main() { MyClass x1; auto y1 = f(MyClass(x1)); // Result: x1.m = 0, y1.m = 1 int x2 = 0; auto y2 = f(int(x2)); // Result: x2 = 1, y2 = 1 std::cout << x1.m << x2; //assert(x1.m == x2); // FAILED!!! return 0; }
run
|
edit
|
history
|
help
0
rstring
hyy
#9
Two-phase sample with VC++ 2015
Structured Member Value Access Using Structure Member Pointer and Variadic Templates
Catching divide-by-zero with /EHc
map_file_mangling
Computing factorial of an integer with recursion and iteration
Struct packing
DCapSurfaceDesc