i got question pointers:
class cappframework : public ibaseapp { public: cappframework( std::initializer_list< cclientapp* > input ); cappframework( ); ~cappframework( ); void create( ) override; void release( ) override; template< class t > t** request( std::string c_appname ) { ( auto c_app : m_clientapps ) { if ( c_app -> getname( ) == c_appname ) { t** t_app = reinterpret_cast< t** >( c_app ); return t_app; } } return nullptr; } std::vector< cclientapp* >& getclientapps( ); private: std::vector< cclientapp* > m_clientapps; }; void ctest::create( ) { std::cout << "ayye" << std::endl; ctest* test = *( m_framework->request< ctest >( "test" ) ); test -> runtest( ); }
ctest derived class cclientapp.
do need delete test? cause if do, access violation. suppose because "request" returning pointer pointer inside vector, when dereference , delete it, delete object in vector / might still used?
this more of general question. need delete every pointer or pointers dynamically allocated using "new"?
i hope can me.
you don't need delete every pointer, otherwise have write code this:
int main( int argc, char ** argv ) { // stuff delete argv; }
if explicitly create new
, assign pointer new gives raw pointer, need delete
pointer. of course, error prone, , can't made exception-safe, , should using things std::unique_ptr , std::make_unique instead.
Comments
Post a Comment