1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
// declare_no_pointers / undeclare_no_pointers
#include <iostream>
#include <memory>
int main() {
int * foo = new int(1);
int * bar = new int(2);
std::declare_no_pointers (reinterpret_cast<char*>(&bar),sizeof(int*));
std::cout << "*foo: " << *foo << '\n';
if (std::get_pointer_safety() != std::pointer_safety::strict)
std::cout << "*bar: " << *bar << '\n'; // invalid if strict safety
std::undeclare_no_pointers (reinterpret_cast<char*>(&bar),sizeof(int*));
delete bar;
delete foo;
return 0;
}
|