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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:29:16+00:00 2026-05-24T10:29:16+00:00

Here is a small function I’m trying to write to keep track of the

  • 0

Here is a small function I’m trying to write to keep track of the dynamic allocations I use in my functions (tired of writing delete [] all the time).

template <class T>
T* snew(int size, vector<T*> list)
{
    T* pointer = new T[size];
    list.push_back(pointer);
    return pointer;
}

vector<float*> list;
float* myfloat1 = snew<float*>(HEIGHT*WIDTH,list);
float* myfloat2 = snew<float*>(HEIGHT*WIDTH,list);
float* myfloat3 = snew<float*>(HEIGHT*WIDTH,list);

So then when I need to clear the memory I can use:

template <class T>
void sdelete(vector<T*> list)
{
    vector<T*>::iterator it;
    for (it = list.begin(); it != list.end(); ++it){
        delete [] *it
        *it = NULL
    }
}

like this:

sdelete<float*>(list);

When I try to compile I get:

cannot convert parameter 2 from 'std::vector<_Ty>' to 'std::vector<_Ty,_Ax>'

Not sure what it means. Thanks for the insight 🙂

  • 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-24T10:29:17+00:00Added an answer on May 24, 2026 at 10:29 am

    First and foremost, you pass vector<T*> list by value, which means that it gets copied and your global list is left unchanged.

    Do it like this:

    template <class T>
    T* snew(int size, vector<T*>& list)
    

    As for the compilation issue, there’s a typo, you’re applying * one time too much, change the usages to

    float* myfloat1 = snew<float>(HEIGHT*WIDTH,list);
    sdelete<float>(list);
    

    Or you could even rely on compiler’s type inference and just write

    float* myfloat1 = snew(HEIGHT*WIDTH,list);
    sdelete(list);
    

    But the idea as a whole is pretty much a bad one, because if you have a vector already, you don’t want to do new/delete by hand. Just create a vector<float> x(HEIGHT*WIDTH); and use it, it gets removed automatically.

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

Sidebar

Related Questions

Need a small hand here im trying to combine two functions to create a
Trying to write a small function that updates a paragraph with an image's alt
I am stuck with a small problem here.. What i am trying to do
I'm getting crazy with a small problem here, I keep getting an error and
Small design question here. I'm trying to develop a calculation app in C#. I
everyone. Here is a small VBA (Excel) function that i wrote, full of MsgBoxes
Okay so here's my small snippet of code: base.$el.delegate('.mb-panel', 'hover', base.hover = function(){ base.change(
I have a small question in JavaScript. Here is a declaration: function answerToLifeUniverseAndEverything() {
I've got a little stuck with a small problem here: I use serialport communications
I am having a small issue with the mysqli_stmt prepare function. Here is my

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.