I can not use shared_ptr in my project, without boost :(
So, I have a class that looks something like the one below:
class MyClass { private: std::auto_ptr<MyOtherClass> obj; };
Now I want to save instances of the above class in std :: vector. It is safe? I read here that it is wrong to use std :: auto_ptr with STL containers. Does this apply to my situation here?
I posted the question as a follow-up to this answer; see Class containing auto_ptr stored in vector .
, , , , (. ) . ( , ), auto_ptr. transanferring , , , , .
, , , auto_ptr . , , :
, - . , , .
, , MyClass instnace, - auto_ptr , , ( auto_ptr )
BTW:
private: MyClass& operator=( const MyClass& ); MyClass( const MyClass& );
, , .
, auto_ptr, , .
boost:: shared_ptr , , boost.
, boost, , shared\ptr, bcp tool boost:: shared_ptr. hpp . , .
, auto_ptr . undefined. :
push_back
undefined, . , , , , , . -, push_back, resize .., const, T. , T const& . / T(T&) - ! , .
resize
T const&
T(T&)
++ . , . . , .
, (17.4.3.6):
17.4.3.6
( , , , ) ++ , ++. , ., undefined :, , (20.1.5, 23.1, 24.1, 26.1).
( , , , ) ++ , ++. , .
, undefined :
MyClass . auto_ptr < > , ( ) auto_ptr < > . , , .
, auto_pointer, , : sort(), . (sort() quicksort, "" ) , , scpope sort(). , , .
, , auto_ptr, , /, . , :)
, -.
- boost auto_ptr, /.
, , / : ( ), sort().
, auto_ptr , - :
class MyClass { private: const std::auto_ptr<MyOtherClass> obj; // Note const here to keep the pointer from being modified. public: MyClass(const MyClass &other) : obj(new MyOtherClass(*other.obj)) {} MyClass &operator=(const MyClass &other) { *obj = *other.obj; return *this; } };
, , , , auto_ptr. , , auto_ptr. auto_ptrs, , . , .
auto_ptr
auto_ptrs
. auto_ptr , , .
boost:: shared_ptr.
Source: https://habr.com/ru/post/1705635/More articles:The right way to get a lot of data in object oriented PHP5 - oopWhy when calling XMLRPC from iis there is no request to capture a violinist? - asp.netGLib hash loop problem - chow to pass int / char to system () the Linux system call - cSetting a registry key for all users in C # - c #A class containing auto_ptr stored in a vector - c ++To check the day of the week of the month - datereturn multiple columns using Case in Select Satement in Oracle - oraclehttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1705639/how-do-you-detect-if-your-website-visitor-came-from-a-google-search-result&usg=ALkJrhhdeWiTDnWtD-4Fu1_yOij1MjF6PgWPF - привязка к значку меню - .netAll Articles