using shared_ptr in boost

I would like to ask for some help about shared_ptr.

My simple code is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include "boost/smart_ptr.hpp"

using namespace std;

class MyClass
{
    public:
    void welcome(){cout << "hello world!" << endl;}
    ~MyClass()
    {
        cout << "destroyed" << endl;
    }
};

typedef boost::shared_ptr<MyClass> myClassPtr;

int main(int argc, char *argv[])
{    
    myClassPtr ptr(new MyClass);
    ptr->welcome();


    return 0;
}



I tried this code and I didn't see the "destroyed" message. How should I use the shared_ptr?

Thank you the reply!
Works for me.
I forgot to write my compiler... mingw 4.4 It is possible that the boost don't work with mingw 4.4?


I tried in the moorning and it works for me :) Just I have to restart the windows :D
Last edited on
Topic archived. No new replies allowed.