我需要创建两个单独的链表,然后比较它们。但是,当我尝试为构造函数创建具有相同运算符重载的第二个列表时,出现错误:
“多项式2* 类型的值不能用于初始化多项式* 类型的实体”
这是我的这些部分的代码:
标题:
#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 代码:
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)
{}
错误出现在 .cpp 文件的最后一行“next2(nextPtr2)”。“nextPtr2”有下划线