Ticket #3673: weak_ptr.cpp

File weak_ptr.cpp, 595 bytes (added by Olaf Lenz <olaf@…>, 13 years ago)

Testcase for the problem

Line 
1#include <boost/python.hpp>
2#include <boost/shared_ptr.hpp>
3#include <boost/make_shared.hpp>
4#include <boost/weak_ptr.hpp>
5#include <iostream>
6
7using namespace boost::python;
8using namespace boost;
9using namespace std;
10
11class A {
12public:
13 A(int _v) : v(_v) {}
14 int v;
15};
16
17weak_ptr< A > stored_a;
18
19// store a shared_ptr
20void setWeakPtr(shared_ptr< A > a) {
21 stored_a = a;
22}
23
24void outputPtr() {
25 cout << stored_a.lock()->v << endl;
26}
27
28BOOST_PYTHON_MODULE(_weak_ptr)
29{
30 class_< A, shared_ptr< A > >("A", init<int>());
31 def("setWeakPtr", &setWeakPtr);
32 def("outputPtr", &outputPtr);
33}