Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9124175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:30:53+00:00 2026-06-17T06:30:53+00:00

If I have a STL container that takes object pointers as elements, I will

  • 0

If I have a STL container that takes object pointers as elements, I will need to delete the pointers in the destructor of the class that has such a container. Since the operation of deleting a pointer

delete ptr_; 
ptr_ = 0;

might be often used, I wonder if there is a function (or function object) template that does this, defined in boost, or STL or by the standard somewhere as the function object DeletePointer defined in the following example:

#include <list>
#include <algorithm>

template<class Pointer>
class DeletePointer
{
    public: 
        void operator()(Pointer t)
        {
            delete t; 
            t = 0;
        }
};

using namespace std;

int main()
{
    list<double*> doublePtrList;

    doublePtrList.push_back(new double (0));
    doublePtrList.push_back(new double (1));
    doublePtrList.push_back(new double (2));
    doublePtrList.push_back(new double (3));

    for_each(doublePtrList.begin(), doublePtrList.end(), DeletePointer<double*>());
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:30:54+00:00Added an answer on June 17, 2026 at 6:30 am

    If (for some reason) you can’t store smart pointers instead of raw pointers in your collection, consider using a Boost pointer container instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class TContainer that is an aggregate of several stl collections pointers
I recently learned that all stl containers have swap function: i.e. c1.swap(c2); will lead
I have a stl::list containing Widget class objects. They need to be sorted according
I'm looking for a STL container that works like std::multimap, but has constant access
I have an STL container and I need to perform an action on each
If I have a function that returns an STL container am I incurring a
I have a container class (called Atom) that I want to store objects of
Assume I have a template (called ExampleTemplate) that takes two arguments: a container type
I want to have an interface ModelGenerator which has a method generate() that takes
I have two STL containers that I want to merge, removing any elements that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.