I need to create two separate linked lists and then compare them. However, when I try to create a second list with the same operator overloading for the constructor, I get an error:
“A value of type polynomial2* cannot be used to initialize an entity of the type polynomial*”
Here is my code for that sections:
Header:
#include <iostream>
#include <string>
using namespace std;
struct polynomial
{
polynomial();
polynomial(string newCoefficient, string newPower, polynomial *nextPtr);
string coefficient;
string power;
polynomial *next;
};
struct polynomial2
{
polynomial2();
polynomial2(string newCoefficient2, string newPower2, polynomial2 *nextPtr2);
string coefficient2;
string power2;
polynomial *next2;
};
class linkedList
{
public:
linkedList();
void callFunctions();
private:
polynomial *head;
polynomial2 *head2;
void makeList(polynomial *head, polynomial2 *head2);
void showList(polynomial *head);
void compareNodes(polynomial *head, polynomial2 *head2);
};
#endif
/* defined(__Assignment3__Polynomial__) */
.CPP Code:
linkedList::linkedList()
{
head = 0;
};
polynomial::polynomial()
{
coefficient = " ";
power = " ";
next = NULL;
};
polynomial2::polynomial2()
{
coefficient2 = " ";
power2 = " ";
next2 = NULL
};
polynomial::polynomial(string newCoefficient, string newPower, polynomial *nextPtr )
:
coefficient(newCoefficient),
power(newPower),
next(nextPtr)
{}
polynomial2::polynomial2(string newCoefficient2, string newPower2, polynomial2 *nextPtr2)
:
coefficient2(newCoefficient2),
power2(newPower2),
next2(nextPtr2)
{}
The error appears on the last line of the .cpp file at “next2(nextPtr2)”. “nextPtr2” is underlined
In your polynomial2 definition, did you mean to put:
instead of