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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:42:52+00:00 2026-05-14T03:42:52+00:00

I have a constructor that looks like this (in c++): Interpreter::Interpreter() { tempDat ==

  • 0

I have a constructor that looks like this (in c++):

Interpreter::Interpreter() {
        tempDat == new DataObject();
        tempDat->clear();
}

the constructor of dataObject does absolutely nothing, and clear does this:

bool DataObject::clear() {
        //clear the object

        if (current_max_id > 0) {
            indexTypeLookup.clear();
            intData.clear();
            doubleData.clear();
            current_max_id = 0;
        }

}

Those members are defined as follows:

std::map<int, int> indexTypeLookup;
std::map<int, int> intData;
std::map<int, double> doubleData;

Now the strange thing is that I’m getting a segfault on tempDat->clear(); gdb says tempDat is null. How is that possible? The constructor of tempDat cannot fail, it looks like this:

DataObject::DataObject() : current_max_id(0)
{

}

I know there are probably better way’s of making such a data structure, but I really like to know where this segfault problem is coming from..

  • 1 1 Answer
  • 1 View
  • 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-14T03:42:52+00:00Added an answer on May 14, 2026 at 3:42 am
    Interpreter::Interpreter() {
            tempDat == new DataObject(); // <- here
            tempDat->clear();
    }
    

    You’re using == to assign. Use = instead:

            tempDat = new DataObject();
    

    Using == gives you an expression that compares the current value of tempDat (some random garbage) to the address of the newly created DataObject. The result of that expression is immediately discarded, and tempDat remains unchanged. So it still contains random garbage, which happened to be 0 in your debugging session.

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

Sidebar

Related Questions

I have a constructor signature that looks like this. public LocateEditorViewModel( ILocateRepository locateRepository, int
I have a copy constructor that looks like this: Qtreenode(const QtreeNode * & n)
I have a class with a constructor that looks like this: public TimedWorker(int timerInterval,
I have ended up with a constructor that looks like this whilst attempting to
I have a JInternalFrame class with a constructor that looks like this: public MyInternalFrame()
I have a Bean that looks like this Class Person{ private String name; private
Im trying to add an constructor to my webservice, that looks like this: public
I have a piece of code that looks like this: public static T CreateSomething<T>(SomeType
If I have a piece of code that looks like this: - (void)testSomething {
My application I have an application design that looks like this: web application layer

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.