Original Post
If i allocate a std vector with push_back do i have to clear it in the dtor of my class? Thanks.
Quote:
Original post by daniel_i_l
If i allocate a std vector with push_back do i have to clear it in the dtor of my class?
Thanks.
class foo { std::vector< int* > data;public: foo() { data.push_back( new int( 42 ) ); data.push_back( new int( 69 ) ); } ~foo() { //the pointers of type "(int*)" are destroyed by std::vector //however, the two ints of type "(int)" - note that this exactly matches the non-brace/value bit of the new invocation - are *NOT* //You must *delete* *each one* - same applies for pointers about to be .clear()ed, .resize()ed, and/or .pop_back()ed }};This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more