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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:31:42+00:00 2026-06-15T09:31:42+00:00

I am working on a program that derives a Polynomial class from a Function

  • 0

I am working on a program that derives a Polynomial class from a Function class. I am almost complete, but I’m running in to one last problem.

I am invoking an “=” operator. In function main, it looks like this:

f3 = f2 * 2;

f3 and f2 are both Polynomial data types. The multiply operator is overloaded, as well, and has been tested to work. When my program reaches this point, it crashes. Here is the backtrace of the crash:

Program received signal SIGABRT, Aborted.
0x00000000 in ?? ()
(gdb) bt
#0  0x00000000 in ?? ()
#1  0x77cbf8c1 in ntdll!RtlUpdateClonedSRWLock ()
   from /cygdrive/c/Windows/system32/ntdll.dll
#2  0x75ab0816 in WaitForSingleObjectEx ()
   from /cygdrive/c/Windows/syswow64/KERNELBASE.dll
#3  0x000000ec in ?? ()
#4  0x00000000 in ?? ()

Unfortunately, that does not provide me any hints.

Lastly, here is the overloaded operator=:

    Polynomial& Polynomial::operator=(const Polynomial& rhs) {
if(this->a)
    delete [] this->a;
this->setName(rhs.getName());
this->degree = rhs.degree;
a = new double[this->degree];
for(int i = 0; i < this->degree; i++)
{
    this->a[i] = rhs.a[i];
}
return *this;
}

And the header file for the class.

    class Polynomial : public Function
{
    public:
                    Polynomial (const string& name = "unnamed");
                    Polynomial (const Polynomial& rhs);
        void        setCoefficients (int degree, ...);
        int         getDegree() const { return degree; }
        double      operator[] (int i) const;
        double      operator() (double x) const;
        Polynomial  operator* (double c) const;
        Polynomial& operator*= (double c);
        Polynomial& operator=(const Polynomial& rhs);
        void        write(ostream& outfile) const;

    private:
        double*    a;
        int        degree;
};
Polynomial operator* (double c, const Polynomial& p);

Constructors:

   (Polynomial::Polynomial (const string& name) {
    a = new double[1];
    a[0] = 0;
    degree = 0;
    return;
    }

Polynomial::Polynomial (const Polynomial& rhs) {

    //Null a, and then pass over to the overloaded = operator.
    if(this->a)
        delete [] this->a;
    *this = rhs;
    return;
    }

I’m willing to share as much code as necessary. Thank you for any help!

  • 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-15T09:31:43+00:00Added an answer on June 15, 2026 at 9:31 am

    You have both problems with constructor and copy constructor. Copy constructor is constructing object from nothing as normal constructor(but then it copies corresponding values from other object) so you shouldn’t check a value there, just create it. There is no need in blank return operator. Also you have a problem with uncertancy of 0 and 1 size of a. This code would be more common:

    Polynomial::Polynomial (const string& name) : Function(name) {
        a = 0;
        degree = 0;
    }
    
    Polynomial::Polynomial (const Polynomial& rhs) {
    
        setName(rhs.getName());
        degree = rhs.degree;
        if(degree)
        {
            a = new double[degree];
            for(int i = 0; i < degree; i++)
                a[i] = rhs.a[i];
        }
        else
            a = 0;
    }
    
    const Polynomial& Polynomial::operator=(const Polynomial& rhs) {
        if(this != &rhs)
        {
            if(a)
                delete [] a;
            setName(rhs.getName());
            degree = rhs.degree;
            a = new double[degree];
            for(int i = 0; i < degree; i++)
                a[i] = rhs.a[i];
        }
        return *this;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a program that you can select a header from a
I am currently working on program that must read data from a XML stream
I am working on a program that fills an array with data from a
I am working on a program that loads and saves data from text files,
I'm working on a program that will sort files based on extension I currently
I'm working on a program that reads in users input as a string, which
I'm working on a program that asks for input, then calculates and posts the
I am working on a program that uses IE to display its help pages.
I'm working on a program that will need to delete a folder (and then
I'm working on a program that creates thumbnails of JPEG images on the fly.

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.