c++ - Building an Object System Around shared_ptr -


i using shared_ptr garbage collection toy language working on compiles c++. objects derive common base class above there strings , numbers there vectors , maps. on c++ side passed wrapped in shared_ptrs containers hold shared_ptr when destroyed content destroyed too. scheme works feels bit weird in containers base objects holding shared_ptrs. there flaw design? if yes alternative hierarchy around approach?

here's how i'd set up:

namespace toylang {  class object; // main handle type; use object references // replace boost::intrusive_ptr or similar if inefficient typedef std::shared_ptr<object> obj;  class object {     // whatever };  class number : public object {     int x;     // etc };  class array : public object {     std::vector<obj> a;     // etc } 

note toylang arrays in scheme vectors of pointers, giving language reference semantics. in fact quite common in dynamic languages: lisp, python, , others work that. long don't have circular references, shared_ptr's reference counting give proper garbage collection.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -