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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:40:25+00:00 2026-06-02T20:40:25+00:00

I have a list of pointers to objects. What I want to do is

  • 0

I have a list of pointers to objects. What I want to do is read the list and store each object in a dynamic array of that object type. So I do this:

int size = List.size();  // find how many objects in the list
ClassA* object = new ClassA[size];   // create a dynamic array
int counter = 0;
p = List.begin();   // iterator = begining of the list
while( p != List.end() )
{
    object[counter] = (*p)->operator=(*(*p));
                // called like this as this function is in a separate class
    p++;
    counter++;
}

This appears to be what I want which means I need the assignment operator but I am a bit confused as to what to put in it and I am getting stack overflow errors, here is what I thought I needed to do:

 ClassA ClassA::operator =(const ClassA& source)
 {
     ClassA* newObject;
     newObject = new ClassA;
     newObject = source;
     return newObject;

 }

this is a load of BS I no that but in my head this is what I want it to do but I don’t fully understand how I implement it.

If anyone can help or suggest a better way to achieve what I need it would be appreciated.

The reason for doing this is the objects stored on this list are normally iterated through each frame and copied into a temporary object. But the list is not changed during the running of the program, which means I don’t need to copy each frame, only once at the start. And I need a dynamic array because I don’t know how many objects will be stored in the list.

  • 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-02T20:40:26+00:00Added an answer on June 2, 2026 at 8:40 pm

    This could be an operator= implementation:

    ClassA &ClassA::operator =(const ClassA& source) {
        // check for self-assignment
        if(this != &source) {
            // copy instance variables.
            a = source.a; // for example...
        }
        // assignment always returns the lvalue
        return *this;
    }
    

    I don’t know your ClassA‘s instance variables, so you should implement the internal copying.

    On the other hand, when iterating your list, you can copy objects this way:

    object[counter] = (**p);
    

    (**p) returns, first the pointer stored in the iterator, and then dereferences it.

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

Sidebar

Related Questions

I have a List box that I want to display a list of objects,
I have an array of objects that i want to sort by two keys.
I have a list of smart pointers. I want some of these smart pointers
I have a vector of Linked list pointers. Each LinkedList has a head pointer
I have List I want to sort Desc by Priority, which is int and
i have list of rows that user select and i want to delete them,
I have a mother class that stores the pointers to some objects in a
I have a generic list of objects from which I want to whittle down
I want to have a deep copy of an vector with pointers to objects,
I have an array of structs. The struct has two function pointers. Each element

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.