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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:45:18+00:00 2026-05-26T12:45:18+00:00

I am creating a CAD software in which I have a class point &

  • 0

I am creating a CAD software in which I have a class point & a class line.

#include <vector>
using namespace std;
class point
{
private:
    vector<int>* child;
    int id;//this is unique id of a point
    double x;//absolute x, y, z co-ord
    double y;//
    double z;//
};

class line
{
private:
    point *a;
    point *b;
    int id;//this is unique for each line object
}

any line object is the child of 2 point objects.
so if i delete a point of a line then the line object shud also be deleted.
For this i want to store the id of all children (line, circle, triangle,….) of a point object in a vector child (instance variable of class point as shown in code).

my question is is my approach correct?
i mean that, there will be around 100’s of point objects in an execution.
since each vector allocates some extra memory, there will be a lot of allocated memory which will not be used in an execution.
can anybody suggest an alternative way of storing unknown no of int as a sequence in each point object?

  • 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-26T12:45:19+00:00Added an answer on May 26, 2026 at 12:45 pm

    my question is how do i create this vector & where (so that it doesnt go out of scope)?

    You have already done this correctly. I’d suggest that you dont’t use a pointer to your vector but simply a vector itself:

    private:
        vector<int> child;
    

    This makes handling it much easier, and you don’t have to allocate/deallocete it by yourself.


    how do i make my child point to the created vector without memory leak?

    If you really need to have a dynamically allocated pointer, you have to call new and delete. For this to behave correctly, you have to define both a constructor and a destructor in your point class:

    class point
    {
    private:
        point() : child(new vector<int>) {}
        ~point() { delete child; }
    
        vector<int>* child;
        int id;//this is unique id of a point
        double x;//absolute x, y, z co-ord
        double y;//
        double z;//
    };
    

    But I still recommend that you don’t use a pointer to a vector as I have explained above.

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

Sidebar

Related Questions

Creating Traversals for Binary Search Tree with Recursion. void inOrder(void (*inOrderPtr)(T&)) { if(this->left !=
Creating a JApplet I have 2 Text Fields, a button and a Text Area.
When creating a web application, and lets say you have a User object denoting
Creating a site in with FrogCMS and using alot of jquery to create an
We have a platform using VCL TFrame as rendering surface for OpenGL. Using FireMonkey,
Creating an installer for possible remote systems so that if they do not have
Creating a table without tbody using javascript createElement/appendChild will not add tbody in Firebug
Creating sprite sheets aka texture atlases rather than using many hundres of individual images
Creating an index MySQL After I have added the FULLTEXT index, how do I
Creating an iOS app in Flash Builder 4.5 which is a small Hello World

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.