1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
// static_pointer_cast example
#include <iostream>
#include <memory>
int main () {
std::shared_ptr<int> foo;
std::shared_ptr<const int> bar;
foo = std::make_shared<int>(10);
bar = std::const_pointer_cast<const int>(foo);
std::cout << "*bar: " << *bar << '\n';
*foo = 20;
std::cout << "*bar: " << *bar << '\n';
return 0;
}
| |