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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:37:34+00:00 2026-05-26T14:37:34+00:00

I have a class cnList which stores a flexible number of items. This list

  • 0

I have a class cnList which stores a flexible number of items. This list must later be converted to a cnArray object. The list class already implements a method cnArray cnList::toArray() const.

But as you can see, it returns an object, not a reference nor a pointer. But what I have to do after converting the list to an array, is to store this array for later use in a class member, this means, I need to have a pointer to that cnArray object.

Now, the actual problem is, simply using the arrays adress is not an option because it gets freed after the method I’m currently in, ends.

Can I somehow “convert” this object to a pointer and the object isn’t freed anymore ?
Sure, I could copy all entries from the object-array to a pointed-array, but thats not what I want, since it’s not very efficient.

I am aware of the fact that I could implement a method in cnList that returns a pointer to a cnArray object, but I’d like to know if there is around this.

  • 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-26T14:37:34+00:00Added an answer on May 26, 2026 at 2:37 pm

    You can allocate a new cnArray from the heap, constructed from the return value of toArray. If you do it right, Return Value Optimization will allow the compiler to optimize out the redundant copy:

    cnArray *p = new cnArray(list.toArray());
    

    To see that g++’s RVO will eliminate the copy, see http://ideone.com/loXAT

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

Sidebar

Related Questions

I have class like this below shown. which contains the shopping items where the
I'm trying to have a generic 'List' class, which will have: Property: Items -
I have class like this: public class object { [Key] int number; String mystring;
I have Class and Student objects. Both have collection of another as property. Which
I have class LegacyClass which inherits OldBaseClass. I'm considering a change to introduce a
We have class lua. In lua class there is a method registerFunc() which is
I have class that looks like this: class A { public: class variables_map vm
I have class A which has ISerializable implemented for custom serialization. Now i need
I have Class called Person containing to properties, Father and List of Children. I
I have Class which extends JDialog . Have an another JDialog declared inside the

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.