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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:00:31+00:00 2026-05-18T03:00:31+00:00

I have a vector with raw pointers (no, I cannot use smart pointers) and

  • 0

I have a vector with raw pointers (no, I cannot use smart pointers) and I want to add items to the list in a for loop. I’ve made a little trial project, and I wondered if this is considered good C++ code in terms of pointer management.

Please only consider raw pointer management, I am not interested in smart pointers for this particular problem I’m trying to solve.

A simple object:

class Request
{
public:
    std::string name;

};

std::vector<Request*> requests;

for (int i = 0; i < 5; i++)
{
    std::stringstream ss;
    ss << "elemenent ";
    ss << i;

    std::string s = ss.str();

    Request* req = new Request();   
    req->name = s;

    requests.push_back(req);

}

EDIT:

So the problem I am trying to solve is adding the DOMNode* to a vector from this library.
I’m starting to get the feeling that trying to write a wrapper for the parts I need from this library for my project, is a bad idea. Or maybe the library is no good?
I haven’t got it to work properly using smart_ptr, if anybody out there has, then I’d like to hear about it.

  • 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-18T03:00:32+00:00Added an answer on May 18, 2026 at 3:00 am

    Well, this leaks memory, so it is bad. Can you use a Pointer Container?

    The reason this code leaks is because you create objects on the heap using new, but you never call delete on them.

    As for you comment, if you have an object that manually manages some resource, you need The Big Three.

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

Sidebar

Related Questions

I have a raw pointer which points to an array of data. I would
How is STL vector usually implemented? It has a raw storage of char[] which
As a followup to Class containing auto_ptr stored in vector , I believe the
I have the following class definition and it needs a copy constructor so deep
I have opened a shelve using the following code: #!/usr/bin/python import shelve #Module:Shelve is
I have a function named OpenAccount() which takes in the details from the User
Given the following: struct Foo { int bar() const; }; struct IsEqual : public
OK, the question title is a bit crappy, but I didn't really know how
Using Boost::Python, the normal mechanism for wrapping functions works correctly with C++ functions returning

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.