The relationship among const_multi_array_ref, multi_array_ref and multi_array is as follows:
multi_array_refis derived fromconst_multi_array_refmulti_arrayis derived frommulti_arry_ref
However, the destructors of const_multi_array_ref and multi_array_ref are non-virtual. In fact they do not have an explicitly implemented destructor. Only multi_array has a one. Does this imply the following usage is not recommended?
multi_array_ref<float, 2> * = new multi_array<float, 2>(extents[3][3]);
If so, why?
multi_arraylibrary classes aren't designed for dynamic polymorphism. They don't have any virtual functions, so it doesn't look reasonable to make destructor virtual too. It's common STL-like design,multi_array_refis just used as unified interface adapter for data owning and non-owning cases.Your usage sample is highly not recommended - it will lead to memory leak because
multi_arraydestructor will not be executed ondeletecall.But it will be safe to access
multi_arrayinstance via reference or pointer tomulti_array_ref.