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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:41:12+00:00 2026-05-18T08:41:12+00:00

The function is this: Set::Set(Multinumber* tempArray[], int tempSize) { numElements = tempSize; capacity =

  • 0

The function is this:

Set::Set(Multinumber* tempArray[], int tempSize)
{
 numElements = tempSize;
 capacity = tempSize*2;
 setArray = new Multinumber*[capacity];
 for (int i=0; i<numElements; i++)
 {
  addElement(tempArray[i]);
 }
}

The variable setArray is declared in my header to be of type Multinumber**

It segfaults whenever I call it with this:

Multinumber* carr[2];
carr[0]=c4;
carr[1]=c5;
Set setb(carr,2);

c4 and c5 are already declared pointers to objects of the proper type.

Any help would be much appreciated.

EDIT: Code below is addElement function (apologies for the indentation)

const Set Set::operator+(const Set& rhs) const
{
 Set result;
 int i=0, j=0;

 while ((i < numElements) && (j < rhs.numElements))
 {
  Multinumber* toadd=new Multinumber;
  toadd=*(setArray[i]) + *(rhs.setArray[j]);
  result.addElement(toadd);
  i++;
  j++;
 }

 while ((i < numElements))
 {
  result.addElement(setArray[i]);
  i++;
 } 


 while ((j < rhs.numElements))
 {
 result.addElement(rhs.setArray[j]);
 j++;
 }


 return result;
}

EDIT:
Based on numerous cout statements, error seems to be in this function:

 bool Set::isFull()
 {
  return (numElements == capacity);
 }

EDIT: Changed array indices, but still segfaults

  • 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-18T08:41:13+00:00Added an answer on May 18, 2026 at 8:41 am
    carr[1]=c4;
    carr[2]=c5;
    

    Shouldn’t that be

    carr[0]=c4;
    carr[1]=c5;
    

    ?

    Piece of advice: If you load this up in a debugger, such as gdb, it would have identified the culprit line and you would’ve seen your error very quickly.

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

Sidebar

Related Questions

I set a view variable in someAction function like this: $this->view->type = some type;
I'm programming a PL/pgSQL function with this: cols_to_select := according to a set of
I'm trying to set a function to do something like this def __binaryTreeInsert(self, toInsert,
I'm hopeless at Javascript. This is what I have: <script type=text/javascript> function beginrefresh(){ //set
I have a list view with couple of items and i set this function
I wrote the following code in Javascript. function main() { this.a ; this.set =
I'm trying to set a callback function in Jack. This is usually quite simple,
function Set() { // This is the constructor this.values = {}; this.n = 0;
I have one question about sys.setrecursionlimit() From the python docs this function: Set the
I have a problem with a javascript set of functions that I made. This

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.