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

  • Home
  • SEARCH
  • 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 8940137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:58:11+00:00 2026-06-15T10:58:11+00:00

I am working on an assignment creating a polynomial calculator which can perform addition,

  • 0

I am working on an assignment creating a polynomial calculator which can perform addition, subtraction, multiplication and division. When i used the main.cpp provided to test the operator= function, the compiler keep saying: “no operator found which takes a right-hand operand of type ‘Polynomial’.

Here is the error i receive:

main.cpp(61): error C2679: binary '=' : no operator found which takes a right-hand
operand of type 'Polynomial' (or there is no acceptable conversion)
          c:\c++ project\comp2012_assignment_3\comp2012_assignment_3\IntegerPolynomial.h(44):
          could be 'IntegerPolynomial &IntegerPolynomial::operator =(const IntegerPolynomial &)'
          while trying to match the argument list '(IntegerPolynomial, Polynomial)'

below are part of my code:

main.cpp

#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <cmath>
#include <string>
#include "Polynomial.h"
#include "IntegerPolynomial.h"

using namespace std;

template <typename T>
T readPoly(const char* filename) {
    ifstream fin(filename, ifstream::in);
    T temp;
    fin >> temp;
    fin.close();
    return (temp); 
}
int main(void)
{
    Polynomial a = readPoly<Polynomial>("input1.txt");
    Polynomial b = readPoly<Polynomial>("input2.txt");
    Polynomial d;

    b.sort();
    cout << "sorted b=" << b << endl;

    IntegerPolynomial ia = readPoly<IntegerPolynomial>("input1.txt");
    IntegerPolynomial ib = readPoly<IntegerPolynomial>("input2.txt");

    int iarry[5] = {1, 3, 5, 9, 10};
    IntegerPolynomial id(iarry, 5);

    cout << "ia=" << ia <<endl;
    cout << "ib=" << ib <<endl;
    cout << "id=" << id <<endl;

    d=b;
    cout << "d=b=" << d << endl;
    d=ib;
    cout << "d=ib=" << d << endl;
    id=b;
    cout << "id=b=" << id << endl;
    d=a-b;

    return 0;
}

polynomial.h

#ifndef POLYNOMIAL_H
#define POLYNOMIAL_H

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <list>
#include <cstdlib>
#include <cmath>
using namespace std;

class Polynomial
{
  public:
    Polynomial& operator=(const Polynomial& a);
  protected:
    std::list<Term> polyList;
};
#endif

polynomial.cpp

#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <string>
#include <list>
#include "Polynomial.h"
// Assignment operator
Polynomial& Polynomial::operator=(const Polynomial& a) {
    polyList.clear();
    for (std::list<Term>::const_iterator a_iterator = a.polyList.begin(), end = a.polyList.end(); a_iterator != end; ++a_iterator) {
        const Term curr_Term = *a_iterator;
        polyList.push_back(curr_Term);
    }
    return *this;
}

integerpolynomial.h

#ifndef INTEGERPOLYNOMIAL_H
#define INTEGERPOLYNOMIAL_H

#include <iostream>
#include "Polynomial.h"
using namespace std;
class IntegerPolynomial : public Polynomial{
  public:
    // Default constructor 
    IntegerPolynomial();
);
#endif

integerpolynomial.cpp

#include "IntegerPolynomial.h"

using namespace std;

// Default constructor 
IntegerPolynomial::IntegerPolynomial() {
}
// print the polynomial a in decreasing order of exponent
void IntegerPolynomial::print(ostream& os) const {
    os << toString();
}

note: i tried to only include the code section which is related to the problem as the whole file of my code is too long.

what actually is the problem since in the main.cpp

d=b;
cout << "d=b=" << d << endl;
d=ib;
cout << "d=ib=" << d << endl;

works fine.

problem arise for this line.

id=b;

Is there any problem associated with the definition of the function and what is the solution. Thanks a lot.

  • 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-15T10:58:12+00:00Added an answer on June 15, 2026 at 10:58 am

    The problem is that assignment operators are not really inherited – if a class does not declare an assignment operator, the compiler declares one implicitly (see [over.ass]). The implicitly declared copy assignment operator for class X has signature X& operator= (const X&).

    So your code id = b invokes the (implicitly declared) assignment operator for IntegerPolynomial, which expects another IntegerPolynomial on the right-hand side.

    If you need to assign arbitrary Polynomials into IntegerPolynomials, you’ll have to define such an assignment operator explicitly. I think you’d have to do this anyway: how would you generically assign a general polynomial to an integral one?

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

Sidebar

Related Questions

I'm working on an assignment which involves making an RPN calculator. I am currently
I'm working on assignment here, part of which requires me to parse integers from
I'm working on a networking assignment and we are tasked with creating a remote
I am working on creating a threadpool from scratch as part of an assignment
I am working on a assignment in which there is a need to calculate
I am creating a VB 2008 change calculator as an assignment. The program is
I'm currently working on an assignment that has me creating a Map class in
For an assignment, I am working on creating a time aware shell. The shell
i`m working on my assignment for univ, and since some parts are not really
I'm working on my assignment of PHP course. The problem that I don't understand

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.