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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:53:53+00:00 2026-05-30T14:53:53+00:00

I writing an application that pushes data over an external service to some server.

  • 0

I writing an application that pushes data over an external service to some server. There is a defined structure that I have to use for this, and it looks like this:

class A {
    B *b; // Another class built the same principle
    C *c; // And another one
    ...
};

and it somewhere boils down to

class XY {
    double *some_val;
    std::string *another_val;
    ...
};

The problem I am facing is that I am only dealing with pointers of pointers of pointers if you will, and I haven’t figured out yet what would be the best way of dealing with these structures.

I could handle memory management myself with new and delete, but I would have to do massive cleanup afterwards and chances that I forget to clean something up and my program leaks are too high in my opinion.

I could declare the classes locally and fill them up that way, but I would have to declare every variable beforehand then, so I have to analyze the class hierachy before I can do anything and after that it will still get really messy.

Smart pointers came in my mind as well, but since they are basically a class wrapping a pointer I would have to declare them beforehand as well, the advantages over the previous method seem to be small.

Does anyone know a smart and, most of all, readable/maintainable method to handle these massive pointer structures?

Update:

If anyone runs into the same problem, this is my approach now (though I still think it’s messy!):

#include <boost/shared_ptr.hpp>
#include <boost/any.hpp>

class A {
    B *b_;
    double *d_;
};

int main() {
    std::vector<boost::any> vp;

    // Create instance of A
    vp.push_back(boost::shared_ptr<A>(new A));
    A *a = boost::any_cast<boost::shared_ptr<A> >(vp.back()).get();

    // Create instance of B in A
    vp.push_back(boost::shared_ptr<B>(new B));
    a->b_ = boost::any_cast<boost::shared_ptr<B> >(vp.back()).get();

    // etc.

    return 0;
}

Update 2:

#include <boost/shared_ptr.hpp>

typedef std::vector<boost::shared_ptr<void> > MemoryManager;

template <class T> T* create_managed(T *ptr, MemoryManager &memorymanager) {
    memorymanager.push_back(boost::shared_ptr<T>(ptr));
    return boost::static_pointer_cast<T>(memorymanager.back()).get();
}

int main() {
    MemoryManager mm;
    A *a = create_managed(new A, mm);
    a->b_ = create_managed(new B, mm);
    return 0;
}
  • 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-30T14:53:54+00:00Added an answer on May 30, 2026 at 2:53 pm

    Consider using smart pointers, they have a big advantage:

    To be smarter than regular pointers, smart pointers need to do things that regular pointers don’t. What could these things be? Probably the most common bugs in C++ (and C) are related to pointers and memory management: dangling pointers, memory leaks, allocation failures and other joys. Having a smart pointer take care of these things and can save a lot of aspirin…

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

Sidebar

Related Questions

I'm writing an application that makes use of a tree structure, so of course
I'm writing an application that on some stage performs low-level disk operations in Linux
I am writing an application that needs to bring window of an external app
I writing simple application that need to make some record of the incoming sound.
I'm writing an application that loads some javascript into a WebBrowser object. To prevent
I am writing an application that is accepting POST data from a third party
We have an application that will be collecting data and storing it in local
I'm writing an application that reads from a MySQL database and migrates data into
I have started writing an application that gets in a certain website and gets
I'm writing an application that requires all users to access data on a central

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.