First off, here is my code:
Part of Header File:
struct polynomial
{
polynomial();
polynomial(string newCoefficient, string newPower, polynomial *nextPtr);
string coefficient;
string power;
polynomial *next;
};
class linkedList
{
public:
void makeList();
private:
polynomial *head;
};
.cpp File:
polynomial:: polynomial ( string newCoefficient, string newPower, polynomial *nextPtr )
:
coefficient(newCoefficient),
power(newPower),
next(nextPtr)
{}
void linkedList::makeList()
{
polynomial poly;
string input1, input2;
cin >> input1;
cin >> input2;
while (input1 != "-999" && input2 != "-999")
{
poly *newNode = new polynomial (input1, input2, next);
next = newNode;
cin >> input1;
cin >> input2;
}
}
However, the problem lies in these two lines of code:
poly *newNode = new polynomial (input1, input2, next);
next = newNode;
In the first line, it says that newNode is an undeclared identifier. It also says:
Polynomial::polynomial(std::string,std::string,polynomial *)’ : cannot convert parameter 3 from ‘InIt (_cdecl *)(_InIt,iterator_traits<_Iter>::difference_type)’ to ‘polynomial *’
1> Context does not allow for disambiguation of overloaded function
In line two, it says newNode is undeclared once again.
What is the issue here? 🙁 I am trying to place values in the struct in the linked list. After coding a bit more, I want to create a new linked list whenever they input the two values.
You never declared
next, andpolyis a variable, not a type. Should bepolynomial *poly, thenpoly = new polynomial(input1, input2, next);.