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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:46:46+00:00 2026-06-12T07:46:46+00:00

In my project I have two classes, the EarleyParser class: class EarleyParser { public:

  • 0

In my project I have two classes, the EarleyParser class:

class EarleyParser
{

    public:

        EarleyParser();
        virtual ~EarleyParser();

        void initialize( string filePath, bool probabilityParse );

    private:

        bool probabilityParser;

        typedef unordered_map< string, list<Production> > productionHashTable;
        productionHashTable earlyHashTable;

};

and the Production class:

class Production
{
    public:

        Production();

        Production( float productionProbability, int productionLength, vector< string >* productionContent );

        Production( const Production& copy_me );

        virtual ~Production();

        float getProductionProbability();
        int getProductionLength();
        vector< string >* getProductionContent();

    private:

        float productionProbability;
        int productionLength;
        vector< string >* productionContent;

        void setProductionProbability( float productionProbability );
        void setProductionLength( int productionLength );
        void setProductionContent( vector< string >* productionContent );

};

As you can see above the EarlyParser class has a member element that is an unordered_map, whose key element is a string and value is a list of elements from the Production class.

The code works correctly, and the unordered_map and list get populated, but when calling the standard destructor class of the EarleyParser I get a segmentation fault.

As I understand the default destructor of EarleyParser should call the default destructor of the unordered_map which should call the one of the list which should call for each of its elements the default destructor of the Production class, which is the following:

Production::~Production()
{
    if( this->productionContent != NULL )
        delete this->productionContent; <- line 44
}

Back tracing with Valgrind and GDB didn’t give me much help on how to solve the segmentation fault, which is given exactly in the EarleyParser.cpp at the line 44 of destructor.

Should I implement the destructor class, or should the default destructor be ok?
Any ideas on what could be causing the segmentation fault?

ADDED COPY CONSTRUCTOR

Production::Production( const Production& copy_me )
{
    if( this->productionContent != NULL )
        this->productionContent = NULL;

    this->setProductionProbability( copy_me.productionProbability );
    this->setProductionLength( copy_me.productionLength );

    this->setProductionContent( copy_me.productionContent );

}
  • 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-12T07:46:48+00:00Added an answer on June 12, 2026 at 7:46 am

    Your Rule of Three is incomplete. Since you have a pointer member, you want to make sure have implemented the copy constructor, copy assignment operator and destructor.

    Now, because you have a pointer to vector member, I’m going to tell you that you shouldn’t have that, but instead just have a std::vector<std::string> or a std::unique_ptr<std::vector<std::string> >.

    I don’t know why you decided there was a need to hold a pointer to a container, but it’s mostly not a good reason, and it’s error prone.

    You could hold a reference to a container, but you need to make sure it’s initialized in the ctor.

    The problem with pointers is that they are too easily grabbed for as a “solution” but in reality are extremely error prone and hard to use. If you stopped thinking about pointers and stopped being inclined to use them at every turn, you’d have a much easier time of it.

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

Sidebar

Related Questions

I have two classes in two files in a class library project, they are:
I have two classes defined as such: public class Questionnaire { public int QuestionnaireID
I have created two classes: public class Params : List<Param> { } public class
I've two classes: User and Project. The project class have ONE user (the owner
Need to add two same name .csproj class libraries in my solution.Have two project
I have two classes, Phone.class and Time.class. I would like to use their methods
I use JPA and Hibernate for my project. I have two classes with same
I have two maven projects, the second project extends some classes of first project.
I am using spring + hibernate in my project; I have two classes Reminder
I have two classes in a different projects. I am importing the project that

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.