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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:49:59+00:00 2026-05-26T16:49:59+00:00

I have a Tree class of the following type class Tree{ private: Node *root;

  • 0

I have a Tree class of the following type

class Tree{
   private:
        Node *root;                         // trie root node 
        unordered_map<int, vector<Node*> > *index; 
        unsigned long long size;
        int count;
    public:
    ................
};

I am having a vector of the following type

vector<Tree> vect;

With the above declaration I am encountering a segmentation fault when a number of nodes are added to each of the Tree.

But the same works perfectly when I use the following declaration

vector<Tree*> vect;

and allocate each Tree* pointer explicitly on the heap using new

The segmentation fault seems as if it occurs because of excessive memory utilization of the stack.

And from a previous question in stack overflow I was told that in the first declaration each Tree object will be allocated on the heap.

Any thoughts on 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-26T16:49:59+00:00Added an answer on May 26, 2026 at 4:49 pm

    With your little code, I guess you have problems in your copy constructor and operator=. Each time you add new item in your vector, there is a copy invocation. In the case of vector of pointers, there is no problems, but with your class, you will have problems with your pointer and map. Implement these methods correctly and try again.

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

Sidebar

Related Questions

I have a binary tree class that is created with a root node and
Im having a problem with python.. I have a binary tree node type: class
I have this very simple C++ class: class Tree { public: Node *head; };
I have the following Object: public class Constraint { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) int id; String
I have the following class called Tree that builds a simple tree class Tree
I have class like following: public class Tree<T extends Comparable<? super T>> { //
I have tree control object created using CTreeCtrl MFC class. The tree control needs
I have a tree of active record objects, something like: class Part < ActiveRecord::Base
So I have a Tree<E> class where E is the datatype held and organized
I have a business object project, which contains composite structure: public class Tree {

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.