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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:23:08+00:00 2026-05-22T12:23:08+00:00

I Have a similar issue like the one listed here pointer-to-a-pointer-to-a-struct-giving-headache my issue is

  • 0

I Have a similar issue like the one listed here pointer-to-a-pointer-to-a-struct-giving-headache
my issue is different because i don’t want multi instances from LISTOFONES i want Multi instances of ONE’s Pointers like

class ONE {  
    int id;  
    char *name;  
};

class LISTOFONES {
    ONE **pointers;
    char *name;

    LISTOFONES ();
    ~LISTOFONES ();
};  

What to do to have a correct and memory safe initialization of the pointers variable with
1- pure c++ .. not stl containers
2- 100% dynamic not [] array limitation
3- Completely Memory Safe ( All Pointers safely point to a valid class too )

EDIT:
This is Not Home Work
and For what i want i only want to know what is the method to correctly init the pointers in the ‘pointers’ variable

EDIT
I Am trying to Achieve a Pointer List (array) Pointed by the Pointer pointers
Each Pointer points to the ONE struct

  • 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-22T12:23:09+00:00Added an answer on May 22, 2026 at 12:23 pm

    If it were me, I would allocate an array of ONE*s thus:

    pointers = new ONE*[reserve];
    

    I would arrange that the first several members of the pointers array pointed to valid ONE objects. The last remaining members would all be zero (not essential, since they will never be derferenced.)

    When I needed to grow the array, I would call new with a bigger size:

    newPointers = new ONE*[newReserve];
    

    and I would copy all of the pointers from previous array to the new array.

    void
    LISTOFONES::push_back(const ONE& one) {
      if(_size>=_reserve) {
        std::size_t newReserve = _reserve?(_reserve*2):1;
        ONE** newPointers = new ONE*[newReserve];
        std::copy(this->pointers, this->pointers+_size, newPointers);
        std::fill(newPointers+_size, newPointers+newReserve, (ONE*)0);
        std::swap(this->pointers, newPointers);
        _reserve = newReserve;
        delete[] newPointers;
      }
      this->pointers[_size] = new ONE(one);
      ++_size;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

my issue is a bit similar to this one: Having an issue with my
I have asked something similar before, but never go to the solution I need.
I was intending to create a splash screen like the one sported by Visual
I have a readData() function that reads files a returns a few different objects
Similar question to, Does it make sense to have multiple tomcat instances on the
I am stuck with what looks like a simple conceptual issue to me. After
Hopefully this is a quick one, and Easy if you know how... I'm writing
I have built ASP.NET app. I need to utilize a third party COM object
Consider an implementation of the Repository Pattern (or similar). I'll try to keep the
This question was asked quite some time ago, and while it covers possible solutions

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.