Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Smart pointer m...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 44202 of 48022
Post > Topic >>

Smart pointer member variables

by cleerline <cleerline@[EMAIL PROTECTED] > Mar 29, 2008 at 06:55 PM

Hi there,

I have the following code:

in .h file i have

class myclass
{
....
....
tile_list* my_tile_list;
....
....
}

in .cpp file I have

....
....
my_tile_list = new tile_list(a, b); 
....
....

Now, i am trying to replace the pointers to tile_list with a smart
point (specificly the boost shared_ptr smart pointer)

Now, in the docs it says "replace all occurrances of new with
shared_ptr<T> p(new Y)

Now, I can do this when I have somthing like:

tile_list* x = new tile_list(a, b);

it becomes:

shared_ptr<tile_list> p(new tile_list(a,b));

it compiles and all is well.

HOWEVER, how do i do the same thing for the pointers which are member
variables?

They are declared and instantiated in different places.

I have tried the following:

class myclass
{
....
....
shared_ptr<tile_list> p;
....
....
}

in .cpp file I have

....
....
shared_ptr<tile_list> p(new tile_list(a,b)); 
....
....

but this does not work.

How do I do this??

thanks for any help.

Cleerline
 




 3 Posts in Topic:
Smart pointer member variables
cleerline <cleerline@[  2008-03-29 18:55:19 
Re: Smart pointer member variables
Lance Diduck <lancedid  2008-03-29 11:59:52 
Re: Smart pointer member variables
cleerline <cleerline@[  2008-03-29 23:29:24 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Oct 14 11:20:14 CDT 2008.