File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change 987987Typically, a shared pointer is first initialized with a newly-allocated object, something like this:
988988
989989 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
990- shared_ptr< thing> thing_ptr = make_shared< thing> (1, true );
991- auto thing2_ptr = make_shared< thing2> (2, false );
990+ shared_ptr< thing> thing_ptr = make_shared< thing> (thing_constructor_params ... );
991+ auto thing2_ptr = make_shared< thing2> (thing2_constructor_params ... );
992992 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
993993 [Listing [shared-ptr]: An example allocation using `shared_ptr`]
994994
995- `make_shared< thing> (1, true )` allocates a new instance of type `thing`, using the constructor
996- arguments `(1, true)` . It returns a `shared_ptr< thing> `. This can be simplified as in the second
997- line with the `auto` type declaration, because the type is sufficiently defined by the return type
998- of `make_shared< thing2> `.
995+ `make_shared< thing> (thing_constructor_params ... )` allocates a new instance of type `thing`, using
996+ the constructor parameters . It returns a `shared_ptr< thing> `. The second line shows a simpler form
997+ using the `auto` type declaration ( the type can be automatically deduced by the return type of
998+ `make_shared< thing2> (...) `.
999999</ div>
10001000
10011001We'll use shared pointers in our code, because it allows multiple objects to use a common object
You can’t perform that action at this time.
0 commit comments