Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Copy initialization: overload resolution issue
#define ENABLE_CONST_OPERATOR 0 #include <iostream> using std::cout; struct A { A() = default; template <typename T> A(T&&) { cout << "template constructor\n"; } }; struct B { operator A() { cout << "non-const operator\n"; return { }; } #if ENABLE_CONST_OPERATOR operator A() const { cout << "const operator\n"; return { }; } #endif }; struct C: B { }; void check(A) { } int main() { cout << "const operator enabled: " << ENABLE_CONST_OPERATOR << "\n\n"; cout << "copy from prvalues " "\n"; std::cout << " B to A: "; check(B()); std::cout << " C to A: "; check(C()); cout << "\n" "copy from const lvalues: " "\n"; cout << " B to A: "; const B b; check(b); cout << " C to A: "; const C c; check(c); }
run
|
edit
|
history
|
help
0
delete from list
Error defining lambda inside namespace
inherited
C++ Assignment..
Insertion vs Sort
C++ standard violation: [templates][explicit instantiation][access checking]
visual-wtf
It complies!
Type deduction in VC++
Kare-Küp Tablosu