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 213969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:19:46+00:00 2026-05-11T18:19:46+00:00

For a program of mine I made a small function to clear the various

  • 0

For a program of mine I made a small function to clear the various std::vectors of pointers that I have.

template <class S>
void clearPtrVector(std::vector<S*> &a,int size)
{
    for(size_t i = 0; i < size; i++)
         delete a[i];

    a.clear();
}

I must have done something wrong here though since when calling this function in a destructor like so :

clearPtrVector(neurons,neurons.size());

I get the following undefined reference two times:

undefined reference to `void clearPtrVector<Neuron>(std::vector<Neuron*,std::allocator<Neuron*> >&, int)'

I have to admit I am not familiar with what the std::allocator is, so I can not guess what the problem might be here. Any help is really appreciated. Thanks in advance!

-Lefteris

  • 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-05-11T18:19:46+00:00Added an answer on May 11, 2026 at 6:19 pm

    Hot Fix

    Write following instead:

      template <class Vector>
      void clearPtrVector(Vector &a)
      {
        for(size_t i = 0; i < a.size(); i++)
             delete a[i];
    
        a.clear();
      }
    

    Make sure you define the template somewhere where compiler can see it before each use of the template. If you do not create a declaration, you should be safe, as otherwise you should get a compile error. If you do create a declaration for any reason, be double carefull to include definition everywhere as needed.

    Redesign

    That said, I think the proper solution would be to rethink your design and to use a container which will handle the destruction properly, so that you do not have to do it manually, which is tedious, and almost impossible to do correctly if you need exception safety. Use std::shared_ptr instead of raw pointers, or std::auto_ptr with a container which is able to hold them (std::vector cannot store auto_ptr values). One possible solution would be to use Boost Pointer Container

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

Sidebar

Ask A Question

Stats

  • Questions 123k
  • Answers 123k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I don't know about bad form (a bit harsh) but… May 12, 2026 at 1:08 am
  • Editorial Team
    Editorial Team added an answer Try this: Change your HTML slightly. The "javascript:" prefix isn't… May 12, 2026 at 1:08 am
  • Editorial Team
    Editorial Team added an answer If its ThreadStatic there's one copy per thread. So, by… May 12, 2026 at 1:08 am

Related Questions

I have two separate functions, bar() and foo(). The execution flow of my program
I want to configure my computer so that say every half an hour it
Recently I was talking with a friend of mine who had started a C++
I am looking for reusable open source components. The level of depth, breadth and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.