// SOME_API import / export ( !) // API ( , SOME_API) class SOME_API something { public: // , private: class data; // , SDK, , std::shared_ptr<data> m_data; // , copy-on-write };
// SOME_API class person { public: // const ( ) void set_name(std::string const& name); // - , STL MS std::string // , copy-on-write, std::string const& get_name() const; // vector of child, , // m_children, std::vector<person>& get_children(); // , API // add_child, get_child .. std::vector<person> const& get_children() const; private: std::string m_name; // - , person std::vector<person> m_children; // , - };
person neighbour = granny;
// class person { public: // -, person(); // , void set_name(std::string const& name); // // ( !) std::string const& get_name() const; // // ( !) std::vector<person>& get_children(); // // ( !) std::vector<person> const& get_children() const; private: class data; // double dispatch class data protected, std::shared_ptr<data> m_data; // , }; // , class person::data { public: void set_name(std::string const& name); std::string const& get_name() const; std::vector<person>& get_children(); std::vector<person> const& get_children() const; private: std::string m_name; std::vector<person> m_children; }; // person::person() : m_data(new data) // , . . { } // person person::data // - , // : void person::set_name(std::string const& name) { // , m_data->set_name(name); // operator-> , }
// ! , ! template <class data> class copy_on_write { public: // , , data const* operator -> () const; // , // , "" data* operator -> (); private: mutable std::shared_ptr<data> m_data; // mutable const void ensure_initialized() const; // void ensure_unique(); // }; // template <class data> data const* copy_on_write<data>::operator -> () const { ensure_initialized(); // nullptr return m_data.get(); // const- } template <class data> data* copy_on_write<data>::operator -> () { ensure_unique(); // , return m_data.get(); // } template <class data> void copy_on_write<data>::ensure_initialized() const { if (!m_data) { m_data.reset(new data); // , type_traits } } template <class data> void copy_on_write<data>::ensure_unique() { ensure_initialized(); // if (!m_data.unique()) // unique() std::shared_ptr { m_data.reset(new data(*m_data)); // } }
class person { public: // , ! private: class data; // , API // copy_on_write<data> m_data; };
class person { public: void set_name(std::string const& name); // , std::string get_name() const; // std::string API int get_child_count() const; // person get_child(int index) const; // , void add_child(person); // , void set_child(int index, person const& child); // person private: class data; // , API // copy_on_write<data> m_data; };
#include , person . std::string forward declaration, #include , . :
// <stdfwd> namespace std { template <typename char_type> class allocator; template <typename char_type> struct char_traits; template <typename char_type, typename traits_type, typename allocator_type> class basic_string; // forward declaration std::string typedef basic_string<char, char_traits<char>, allocator<char>> string; // forward declaration std::wstring typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t>> wstring; // , #include <cstddef> std::nullptr_t typedef decltype(nullptr) nullptr_t; }
. , C++ API , , . , , , . API.
" " . , : , . , , :
1) API ( , ... , ?)
2) ,
3) - API, .
, .
:
1. , - , - , -, interface- ( ). - . , :
std::unique_ptr<IAmUselessInterface> something = UserUsefulFactory::CreateSomethingLessUseless<DerivedUsefulClass>(arguments);
, , , double dispatch , , - , private. C++ , - , API -.
2. . . 1 . , !.. , , , , - - ! 1 :
std::unique_ptr<I> something = ::Instance().<>( ::Instance().<>(42)); // : (<>(42));
3. . : , , . , : - . , API, - - -, , . , C++ , , - . , , API .
Boost.Python. object namespace boost::python , Python C++, PyObject* , . PyObject* object ( None - NULL - Python). , , boost::python::dict boost::python::object . , , , , dict object .
double dispatch - , , - , ++ . , :
class person { public: // - protected: class data; data& get_data_reference(); data const& get_data_const_reference() const; private: copy_on_write<data> m_data; }; class VIP : public person { public: // protected: class data; // VIP::data - person::data };
:
person president = VIP("mr. President");
, , -.
, , , , . , - !
API, , .
, --API, , ?
! - , - , . , , !
(Copy-on-write).
(Double dispatch)
- , , .
#include , person . std::string forward declaration, #include , . :
// <stdfwd> namespace std { template <typename char_type> class allocator; template <typename char_type> struct char_traits; template <typename char_type, typename traits_type, typename allocator_type> class basic_string; // forward declaration std::string typedef basic_string<char, char_traits<char>, allocator<char>> string; // forward declaration std::wstring typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t>> wstring; // , #include <cstddef> std::nullptr_t typedef decltype(nullptr) nullptr_t; }
. , C++ API , , . , , , . API.
" " . , : , . , , :
1) API ( , ... , ?)
2) ,
3) - API, .
, .
:
1. , - , - , -, interface- ( ). - . , :
std::unique_ptr<IAmUselessInterface> something = UserUsefulFactory::CreateSomethingLessUseless<DerivedUsefulClass>(arguments);
, , , double dispatch , , - , private. C++ , - , API -.
2. . . 1 . , !.. , , , , - - ! 1 :
std::unique_ptr<I> something = ::Instance().<>( ::Instance().<>(42)); // : (<>(42));
3. . : , , . , : - . , API, - - -, , . , C++ , , - . , , API .
Boost.Python. object namespace boost::python , Python C++, PyObject* , . PyObject* object ( None - NULL - Python). , , boost::python::dict boost::python::object . , , , , dict object .
double dispatch - , , - , ++ . , :
class person { public: // - protected: class data; data& get_data_reference(); data const& get_data_const_reference() const; private: copy_on_write<data> m_data; }; class VIP : public person { public: // protected: class data; // VIP::data - person::data };
:
person president = VIP("mr. President");
, , -.
, , , , . , - !
API, , .
, --API, , ?
! - , - , . , , !
(Copy-on-write).
(Double dispatch)
- , , .
#include , person . std::string forward declaration, #include , . :
// <stdfwd> namespace std { template <typename char_type> class allocator; template <typename char_type> struct char_traits; template <typename char_type, typename traits_type, typename allocator_type> class basic_string; // forward declaration std::string typedef basic_string<char, char_traits<char>, allocator<char>> string; // forward declaration std::wstring typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t>> wstring; // , #include <cstddef> std::nullptr_t typedef decltype(nullptr) nullptr_t; }
. , C++ API , , . , , , . API.
" " . , : , . , , :
1) API ( , ... , ?)
2) ,
3) - API, .
, .
:
1. , - , - , -, interface- ( ). - . , :
std::unique_ptr<IAmUselessInterface> something = UserUsefulFactory::CreateSomethingLessUseless<DerivedUsefulClass>(arguments);
, , , double dispatch , , - , private. C++ , - , API -.
2. . . 1 . , !.. , , , , - - ! 1 :
std::unique_ptr<I> something = ::Instance().<>( ::Instance().<>(42)); // : (<>(42));
3. . : , , . , : - . , API, - - -, , . , C++ , , - . , , API .
Boost.Python. object namespace boost::python , Python C++, PyObject* , . PyObject* object ( None - NULL - Python). , , boost::python::dict boost::python::object . , , , , dict object .
double dispatch - , , - , ++ . , :
class person { public: // - protected: class data; data& get_data_reference(); data const& get_data_const_reference() const; private: copy_on_write<data> m_data; }; class VIP : public person { public: // protected: class data; // VIP::data - person::data };
:
person president = VIP("mr. President");
, , -.
, , , , . , - !
API, , .
, --API, , ?
! - , - , . , , !
(Copy-on-write).
(Double dispatch)
- , , .
#include , person . std::string forward declaration, #include , . :
// <stdfwd> namespace std { template <typename char_type> class allocator; template <typename char_type> struct char_traits; template <typename char_type, typename traits_type, typename allocator_type> class basic_string; // forward declaration std::string typedef basic_string<char, char_traits<char>, allocator<char>> string; // forward declaration std::wstring typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t>> wstring; // , #include <cstddef> std::nullptr_t typedef decltype(nullptr) nullptr_t; }
. , C++ API , , . , , , . API.
" " . , : , . , , :
1) API ( , ... , ?)
2) ,
3) - API, .
, .
:
1. , - , - , -, interface- ( ). - . , :
std::unique_ptr<IAmUselessInterface> something = UserUsefulFactory::CreateSomethingLessUseless<DerivedUsefulClass>(arguments);
, , , double dispatch , , - , private. C++ , - , API -.
2. . . 1 . , !.. , , , , - - ! 1 :
std::unique_ptr<I> something = ::Instance().<>( ::Instance().<>(42)); // : (<>(42));
3. . : , , . , : - . , API, - - -, , . , C++ , , - . , , API .
Boost.Python. object namespace boost::python , Python C++, PyObject* , . PyObject* object ( None - NULL - Python). , , boost::python::dict boost::python::object . , , , , dict object .
double dispatch - , , - , ++ . , :
class person { public: // - protected: class data; data& get_data_reference(); data const& get_data_const_reference() const; private: copy_on_write<data> m_data; }; class VIP : public person { public: // protected: class data; // VIP::data - person::data };
:
person president = VIP("mr. President");
, , -.
, , , , . , - !
API, , .
, --API, , ?
! - , - , . , , !
(Copy-on-write).
(Double dispatch)
- , , .
#include , person . std::string forward declaration, #include , . :
// <stdfwd> namespace std { template <typename char_type> class allocator; template <typename char_type> struct char_traits; template <typename char_type, typename traits_type, typename allocator_type> class basic_string; // forward declaration std::string typedef basic_string<char, char_traits<char>, allocator<char>> string; // forward declaration std::wstring typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t>> wstring; // , #include <cstddef> std::nullptr_t typedef decltype(nullptr) nullptr_t; }
. , C++ API , , . , , , . API.
" " . , : , . , , :
1) API ( , ... , ?)
2) ,
3) - API, .
, .
:
1. , - , - , -, interface- ( ). - . , :
std::unique_ptr<IAmUselessInterface> something = UserUsefulFactory::CreateSomethingLessUseless<DerivedUsefulClass>(arguments);
, , , double dispatch , , - , private. C++ , - , API -.
2. . . 1 . , !.. , , , , - - ! 1 :
std::unique_ptr<I> something = ::Instance().<>( ::Instance().<>(42)); // : (<>(42));
3. . : , , . , : - . , API, - - -, , . , C++ , , - . , , API .
Boost.Python. object namespace boost::python , Python C++, PyObject* , . PyObject* object ( None - NULL - Python). , , boost::python::dict boost::python::object . , , , , dict object .
double dispatch - , , - , ++ . , :
class person { public: // - protected: class data; data& get_data_reference(); data const& get_data_const_reference() const; private: copy_on_write<data> m_data; }; class VIP : public person { public: // protected: class data; // VIP::data - person::data };
:
person president = VIP("mr. President");
, , -.
, , , , . , - !
API, , .
, --API, , ?
! - , - , . , , !
(Copy-on-write).
(Double dispatch)
- , , .
#include , person . std::string forward declaration, #include , . :
// <stdfwd> namespace std { template <typename char_type> class allocator; template <typename char_type> struct char_traits; template <typename char_type, typename traits_type, typename allocator_type> class basic_string; // forward declaration std::string typedef basic_string<char, char_traits<char>, allocator<char>> string; // forward declaration std::wstring typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t>> wstring; // , #include <cstddef> std::nullptr_t typedef decltype(nullptr) nullptr_t; }
. , C++ API , , . , , , . API.
" " . , : , . , , :
1) API ( , ... , ?)
2) ,
3) - API, .
, .
:
1. , - , - , -, interface- ( ). - . , :
std::unique_ptr<IAmUselessInterface> something = UserUsefulFactory::CreateSomethingLessUseless<DerivedUsefulClass>(arguments);
, , , double dispatch , , - , private. C++ , - , API -.
2. . . 1 . , !.. , , , , - - ! 1 :
std::unique_ptr<I> something = ::Instance().<>( ::Instance().<>(42)); // : (<>(42));
3. . : , , . , : - . , API, - - -, , . , C++ , , - . , , API .
Boost.Python. object namespace boost::python , Python C++, PyObject* , . PyObject* object ( None - NULL - Python). , , boost::python::dict boost::python::object . , , , , dict object .
double dispatch - , , - , ++ . , :
class person { public: // - protected: class data; data& get_data_reference(); data const& get_data_const_reference() const; private: copy_on_write<data> m_data; }; class VIP : public person { public: // protected: class data; // VIP::data - person::data };
:
person president = VIP("mr. President");
, , -.
, , , , . , - !
API, , .
, --API, , ?
! - , - , . , , !
(Copy-on-write).
(Double dispatch)
- , , .
#include , person . std::string forward declaration, #include , . :
// <stdfwd> namespace std { template <typename char_type> class allocator; template <typename char_type> struct char_traits; template <typename char_type, typename traits_type, typename allocator_type> class basic_string; // forward declaration std::string typedef basic_string<char, char_traits<char>, allocator<char>> string; // forward declaration std::wstring typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t>> wstring; // , #include <cstddef> std::nullptr_t typedef decltype(nullptr) nullptr_t; }
. , C++ API , , . , , , . API.
" " . , : , . , , :
1) API ( , ... , ?)
2) ,
3) - API, .
, .
:
1. , - , - , -, interface- ( ). - . , :
std::unique_ptr<IAmUselessInterface> something = UserUsefulFactory::CreateSomethingLessUseless<DerivedUsefulClass>(arguments);
, , , double dispatch , , - , private. C++ , - , API -.
2. . . 1 . , !.. , , , , - - ! 1 :
std::unique_ptr<I> something = ::Instance().<>( ::Instance().<>(42)); // : (<>(42));
3. . : , , . , : - . , API, - - -, , . , C++ , , - . , , API .
Boost.Python. object namespace boost::python , Python C++, PyObject* , . PyObject* object ( None - NULL - Python). , , boost::python::dict boost::python::object . , , , , dict object .
double dispatch - , , - , ++ . , :
class person { public: // - protected: class data; data& get_data_reference(); data const& get_data_const_reference() const; private: copy_on_write<data> m_data; }; class VIP : public person { public: // protected: class data; // VIP::data - person::data };
:
person president = VIP("mr. President");
, , -.
, , , , . , - !
API, , .
, --API, , ?
! - , - , . , , !
(Copy-on-write).
(Double dispatch)
- , , .
#include , person . std::string forward declaration, #include , . :
// <stdfwd> namespace std { template <typename char_type> class allocator; template <typename char_type> struct char_traits; template <typename char_type, typename traits_type, typename allocator_type> class basic_string; // forward declaration std::string typedef basic_string<char, char_traits<char>, allocator<char>> string; // forward declaration std::wstring typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t>> wstring; // , #include <cstddef> std::nullptr_t typedef decltype(nullptr) nullptr_t; }
. , C++ API , , . , , , . API.
" " . , : , . , , :
1) API ( , ... , ?)
2) ,
3) - API, .
, .
:
1. , - , - , -, interface- ( ). - . , :
std::unique_ptr<IAmUselessInterface> something = UserUsefulFactory::CreateSomethingLessUseless<DerivedUsefulClass>(arguments);
, , , double dispatch , , - , private. C++ , - , API -.
2. . . 1 . , !.. , , , , - - ! 1 :
std::unique_ptr<I> something = ::Instance().<>( ::Instance().<>(42)); // : (<>(42));
3. . : , , . , : - . , API, - - -, , . , C++ , , - . , , API .
Boost.Python. object namespace boost::python , Python C++, PyObject* , . PyObject* object ( None - NULL - Python). , , boost::python::dict boost::python::object . , , , , dict object .
double dispatch - , , - , ++ . , :
class person { public: // - protected: class data; data& get_data_reference(); data const& get_data_const_reference() const; private: copy_on_write<data> m_data; }; class VIP : public person { public: // protected: class data; // VIP::data - person::data };
:
person president = VIP("mr. President");
, , -.
, , , , . , - !
API, , .
, --API, , ?
! - , - , . , , !
(Copy-on-write).
(Double dispatch)
- , , .
#include , person . std::string forward declaration, #include , . :
// <stdfwd> namespace std { template <typename char_type> class allocator; template <typename char_type> struct char_traits; template <typename char_type, typename traits_type, typename allocator_type> class basic_string; // forward declaration std::string typedef basic_string<char, char_traits<char>, allocator<char>> string; // forward declaration std::wstring typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t>> wstring; // , #include <cstddef> std::nullptr_t typedef decltype(nullptr) nullptr_t; }
. , C++ API , , . , , , . API.
" " . , : , . , , :
1) API ( , ... , ?)
2) ,
3) - API, .
, .
:
1. , - , - , -, interface- ( ). - . , :
std::unique_ptr<IAmUselessInterface> something = UserUsefulFactory::CreateSomethingLessUseless<DerivedUsefulClass>(arguments);
, , , double dispatch , , - , private. C++ , - , API -.
2. . . 1 . , !.. , , , , - - ! 1 :
std::unique_ptr<I> something = ::Instance().<>( ::Instance().<>(42)); // : (<>(42));
3. . : , , . , : - . , API, - - -, , . , C++ , , - . , , API .
Boost.Python. object namespace boost::python , Python C++, PyObject* , . PyObject* object ( None - NULL - Python). , , boost::python::dict boost::python::object . , , , , dict object .
double dispatch - , , - , ++ . , :
class person { public: // - protected: class data; data& get_data_reference(); data const& get_data_const_reference() const; private: copy_on_write<data> m_data; }; class VIP : public person { public: // protected: class data; // VIP::data - person::data };
:
person president = VIP("mr. President");
, , -.
, , , , . , - !
API, , .
, --API, , ?
! - , - , . , , !
(Copy-on-write).
(Double dispatch)
- , , .
#include , person . std::string forward declaration, #include , . :
// <stdfwd> namespace std { template <typename char_type> class allocator; template <typename char_type> struct char_traits; template <typename char_type, typename traits_type, typename allocator_type> class basic_string; // forward declaration std::string typedef basic_string<char, char_traits<char>, allocator<char>> string; // forward declaration std::wstring typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t>> wstring; // , #include <cstddef> std::nullptr_t typedef decltype(nullptr) nullptr_t; }
. , C++ API , , . , , , . API.
" " . , : , . , , :
1) API ( , ... , ?)
2) ,
3) - API, .
, .
:
1. , - , - , -, interface- ( ). - . , :
std::unique_ptr<IAmUselessInterface> something = UserUsefulFactory::CreateSomethingLessUseless<DerivedUsefulClass>(arguments);
, , , double dispatch , , - , private. C++ , - , API -.
2. . . 1 . , !.. , , , , - - ! 1 :
std::unique_ptr<I> something = ::Instance().<>( ::Instance().<>(42)); // : (<>(42));
3. . : , , . , : - . , API, - - -, , . , C++ , , - . , , API .
Boost.Python. object namespace boost::python , Python C++, PyObject* , . PyObject* object ( None - NULL - Python). , , boost::python::dict boost::python::object . , , , , dict object .
double dispatch - , , - , ++ . , :
class person { public: // - protected: class data; data& get_data_reference(); data const& get_data_const_reference() const; private: copy_on_write<data> m_data; }; class VIP : public person { public: // protected: class data; // VIP::data - person::data };
:
person president = VIP("mr. President");
, , -.
, , , , . , - !
API, , .
, --API, , ?
! - , - , . , , !
(Copy-on-write).
(Double dispatch)
- , , .
#include , person . std::string forward declaration, #include , . :
// <stdfwd> namespace std { template <typename char_type> class allocator; template <typename char_type> struct char_traits; template <typename char_type, typename traits_type, typename allocator_type> class basic_string; // forward declaration std::string typedef basic_string<char, char_traits<char>, allocator<char>> string; // forward declaration std::wstring typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t>> wstring; // , #include <cstddef> std::nullptr_t typedef decltype(nullptr) nullptr_t; }
. , C++ API , , . , , , . API.
" " . , : , . , , :
1) API ( , ... , ?)
2) ,
3) - API, .
, .
:
1. , - , - , -, interface- ( ). - . , :
std::unique_ptr<IAmUselessInterface> something = UserUsefulFactory::CreateSomethingLessUseless<DerivedUsefulClass>(arguments);
, , , double dispatch , , - , private. C++ , - , API -.
2. . . 1 . , !.. , , , , - - ! 1 :
std::unique_ptr<I> something = ::Instance().<>( ::Instance().<>(42)); // : (<>(42));
3. . : , , . , : - . , API, - - -, , . , C++ , , - . , , API .
Boost.Python. object namespace boost::python , Python C++, PyObject* , . PyObject* object ( None - NULL - Python). , , boost::python::dict boost::python::object . , , , , dict object .
double dispatch - , , - , ++ . , :
class person { public: // - protected: class data; data& get_data_reference(); data const& get_data_const_reference() const; private: copy_on_write<data> m_data; }; class VIP : public person { public: // protected: class data; // VIP::data - person::data };
:
person president = VIP("mr. President");
, , -.
, , , , . , - !
API, , .
, --API, , ?
! - , - , . , , !
(Copy-on-write).
(Double dispatch)
- , , .
#include , person . std::string forward declaration, #include , . :
// <stdfwd> namespace std { template <typename char_type> class allocator; template <typename char_type> struct char_traits; template <typename char_type, typename traits_type, typename allocator_type> class basic_string; // forward declaration std::string typedef basic_string<char, char_traits<char>, allocator<char>> string; // forward declaration std::wstring typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t>> wstring; // , #include <cstddef> std::nullptr_t typedef decltype(nullptr) nullptr_t; }
. , C++ API , , . , , , . API.
" " . , : , . , , :
1) API ( , ... , ?)
2) ,
3) - API, .
, .
:
1. , - , - , -, interface- ( ). - . , :
std::unique_ptr<IAmUselessInterface> something = UserUsefulFactory::CreateSomethingLessUseless<DerivedUsefulClass>(arguments);
, , , double dispatch , , - , private. C++ , - , API -.
2. . . 1 . , !.. , , , , - - ! 1 :
std::unique_ptr<I> something = ::Instance().<>( ::Instance().<>(42)); // : (<>(42));
3. . : , , . , : - . , API, - - -, , . , C++ , , - . , , API .
Boost.Python. object namespace boost::python , Python C++, PyObject* , . PyObject* object ( None - NULL - Python). , , boost::python::dict boost::python::object . , , , , dict object .
double dispatch - , , - , ++ . , :
class person { public: // - protected: class data; data& get_data_reference(); data const& get_data_const_reference() const; private: copy_on_write<data> m_data; }; class VIP : public person { public: // protected: class data; // VIP::data - person::data };
:
person president = VIP("mr. President");
, , -.
, , , , . , - !
API, , .
, --API, , ?
! - , - , . , , !
(Copy-on-write).
(Double dispatch)
- , , .
#include , person . std::string forward declaration, #include , . :
// <stdfwd> namespace std { template <typename char_type> class allocator; template <typename char_type> struct char_traits; template <typename char_type, typename traits_type, typename allocator_type> class basic_string; // forward declaration std::string typedef basic_string<char, char_traits<char>, allocator<char>> string; // forward declaration std::wstring typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t>> wstring; // , #include <cstddef> std::nullptr_t typedef decltype(nullptr) nullptr_t; }
. , C++ API , , . , , , . API.
" " . , : , . , , :
1) API ( , ... , ?)
2) ,
3) - API, .
, .
:
1. , - , - , -, interface- ( ). - . , :
std::unique_ptr<IAmUselessInterface> something = UserUsefulFactory::CreateSomethingLessUseless<DerivedUsefulClass>(arguments);
, , , double dispatch , , - , private. C++ , - , API -.
2. . . 1 . , !.. , , , , - - ! 1 :
std::unique_ptr<I> something = ::Instance().<>( ::Instance().<>(42)); // : (<>(42));
3. . : , , . , : - . , API, - - -, , . , C++ , , - . , , API .
Boost.Python. object namespace boost::python , Python C++, PyObject* , . PyObject* object ( None - NULL - Python). , , boost::python::dict boost::python::object . , , , , dict object .
double dispatch - , , - , ++ . , :
class person { public: // - protected: class data; data& get_data_reference(); data const& get_data_const_reference() const; private: copy_on_write<data> m_data; }; class VIP : public person { public: // protected: class data; // VIP::data - person::data };
:
person president = VIP("mr. President");
, , -.
, , , , . , - !
API, , .
, --API, , ?
! - , - , . , , !
(Copy-on-write).
(Double dispatch)
- , , .
#include , person . std::string forward declaration, #include , . :
// <stdfwd> namespace std { template <typename char_type> class allocator; template <typename char_type> struct char_traits; template <typename char_type, typename traits_type, typename allocator_type> class basic_string; // forward declaration std::string typedef basic_string<char, char_traits<char>, allocator<char>> string; // forward declaration std::wstring typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t>> wstring; // , #include <cstddef> std::nullptr_t typedef decltype(nullptr) nullptr_t; }
. , C++ API , , . , , , . API.
" " . , : , . , , :
1) API ( , ... , ?)
2) ,
3) - API, .
, .
:
1. , - , - , -, interface- ( ). - . , :
std::unique_ptr<IAmUselessInterface> something = UserUsefulFactory::CreateSomethingLessUseless<DerivedUsefulClass>(arguments);
, , , double dispatch , , - , private. C++ , - , API -.
2. . . 1 . , !.. , , , , - - ! 1 :
std::unique_ptr<I> something = ::Instance().<>( ::Instance().<>(42)); // : (<>(42));
3. . : , , . , : - . , API, - - -, , . , C++ , , - . , , API .
Boost.Python. object namespace boost::python , Python C++, PyObject* , . PyObject* object ( None - NULL - Python). , , boost::python::dict boost::python::object . , , , , dict object .
double dispatch - , , - , ++ . , :
class person { public: // - protected: class data; data& get_data_reference(); data const& get_data_const_reference() const; private: copy_on_write<data> m_data; }; class VIP : public person { public: // protected: class data; // VIP::data - person::data };
:
person president = VIP("mr. President");
, , -.
, , , , . , - !
API, , .
, --API, , ?
! - , - , . , , !
(Copy-on-write).
(Double dispatch)
- , , .
#include , person . std::string forward declaration, #include , . :
// <stdfwd> namespace std { template <typename char_type> class allocator; template <typename char_type> struct char_traits; template <typename char_type, typename traits_type, typename allocator_type> class basic_string; // forward declaration std::string typedef basic_string<char, char_traits<char>, allocator<char>> string; // forward declaration std::wstring typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t>> wstring; // , #include <cstddef> std::nullptr_t typedef decltype(nullptr) nullptr_t; }
. , C++ API , , . , , , . API.
" " . , : , . , , :
1) API ( , ... , ?)
2) ,
3) - API, .
, .
:
1. , - , - , -, interface- ( ). - . , :
std::unique_ptr<IAmUselessInterface> something = UserUsefulFactory::CreateSomethingLessUseless<DerivedUsefulClass>(arguments);
, , , double dispatch , , - , private. C++ , - , API -.
2. . . 1 . , !.. , , , , - - ! 1 :
std::unique_ptr<I> something = ::Instance().<>( ::Instance().<>(42)); // : (<>(42));
3. . : , , . , : - . , API, - - -, , . , C++ , , - . , , API .
Boost.Python. object namespace boost::python , Python C++, PyObject* , . PyObject* object ( None - NULL - Python). , , boost::python::dict boost::python::object . , , , , dict object .
double dispatch - , , - , ++ . , :
class person { public: // - protected: class data; data& get_data_reference(); data const& get_data_const_reference() const; private: copy_on_write<data> m_data; }; class VIP : public person { public: // protected: class data; // VIP::data - person::data };
:
person president = VIP("mr. President");
, , -.
, , , , . , - !
API, , .
, --API, , ?
! - , - , . , , !
(Copy-on-write).
(Double dispatch)
- , , .
#include , person . std::string forward declaration, #include , . :
// <stdfwd> namespace std { template <typename char_type> class allocator; template <typename char_type> struct char_traits; template <typename char_type, typename traits_type, typename allocator_type> class basic_string; // forward declaration std::string typedef basic_string<char, char_traits<char>, allocator<char>> string; // forward declaration std::wstring typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t>> wstring; // , #include <cstddef> std::nullptr_t typedef decltype(nullptr) nullptr_t; }
. , C++ API , , . , , , . API.
" " . , : , . , , :
1) API ( , ... , ?)
2) ,
3) - API, .
, .
:
1. , - , - , -, interface- ( ). - . , :
std::unique_ptr<IAmUselessInterface> something = UserUsefulFactory::CreateSomethingLessUseless<DerivedUsefulClass>(arguments);
, , , double dispatch , , - , private. C++ , - , API -.
2. . . 1 . , !.. , , , , - - ! 1 :
std::unique_ptr<I> something = ::Instance().<>( ::Instance().<>(42)); // : (<>(42));
3. . : , , . , : - . , API, - - -, , . , C++ , , - . , , API .
Boost.Python. object namespace boost::python , Python C++, PyObject* , . PyObject* object ( None - NULL - Python). , , boost::python::dict boost::python::object . , , , , dict object .
double dispatch - , , - , ++ . , :
class person { public: // - protected: class data; data& get_data_reference(); data const& get_data_const_reference() const; private: copy_on_write<data> m_data; }; class VIP : public person { public: // protected: class data; // VIP::data - person::data };
:
person president = VIP("mr. President");
, , -.
, , , , . , - !
API, , .
, --API, , ?
! - , - , . , , !
(Copy-on-write).
(Double dispatch)
- , , .
#include , person . std::string forward declaration, #include , . :
// <stdfwd> namespace std { template <typename char_type> class allocator; template <typename char_type> struct char_traits; template <typename char_type, typename traits_type, typename allocator_type> class basic_string; // forward declaration std::string typedef basic_string<char, char_traits<char>, allocator<char>> string; // forward declaration std::wstring typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t>> wstring; // , #include <cstddef> std::nullptr_t typedef decltype(nullptr) nullptr_t; }
. , C++ API , , . , , , . API.
" " . , : , . , , :
1) API ( , ... , ?)
2) ,
3) - API, .
, .
:
1. , - , - , -, interface- ( ). - . , :
std::unique_ptr<IAmUselessInterface> something = UserUsefulFactory::CreateSomethingLessUseless<DerivedUsefulClass>(arguments);
, , , double dispatch , , - , private. C++ , - , API -.
2. . . 1 . , !.. , , , , - - ! 1 :
std::unique_ptr<I> something = ::Instance().<>( ::Instance().<>(42)); // : (<>(42));
3. . : , , . , : - . , API, - - -, , . , C++ , , - . , , API .
Boost.Python. object namespace boost::python , Python C++, PyObject* , . PyObject* object ( None - NULL - Python). , , boost::python::dict boost::python::object . , , , , dict object .
double dispatch - , , - , ++ . , :
class person { public: // - protected: class data; data& get_data_reference(); data const& get_data_const_reference() const; private: copy_on_write<data> m_data; }; class VIP : public person { public: // protected: class data; // VIP::data - person::data };
:
person president = VIP("mr. President");
, , -.
, , , , . , - !
API, , .
, --API, , ?
! - , - , . , , !
(Copy-on-write).
(Double dispatch)
- , , .
Source: https://habr.com/ru/post/229327/
All Articles