Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
const_pointer_cast
//Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x64 #include <iostream> #include <memory> struct A { A() { std::cout << "ctor\n"; } ~A() { std::cout << "dtor\n"; } void set(int v) { m_v = v; } int m_v = 0; }; int main() { { std::cout << "1\n"; auto p = std::make_shared<A>(); p->set(10); std::cout << p->m_v << "\n"; auto q = std::const_pointer_cast<const A>(p); // q->set(5); compile error std::cout << q->m_v << "\n"; } std::cout << "Hello, world!\n"; }
run
|
edit
|
history
|
help
0
msvc compile optimization demo...
throwing an exception containing a unique_ptr is dangerous
map_file_mangling
#21.2
Copy_and_base
const reference life time extension
#32
#22.1
infix to postfix v 3.0 with improved eval()
variable template not supported