【问题标题】:Issue with Creating a Linked List创建链接列表的问题
【发布时间】:2013-02-14 23:59:03
【问题描述】:

首先,这是我的代码:

部分头文件:

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 文件:

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;
    }

}

但是,问题在于这两行代码:

poly *newNode = new polynomial (input1, input2, next); 
next = newNode; 

在第一行,它说 newNode 是一个未声明的标识符。它还说:

Polynomial::polynomial(std::string,std::string,polynomial *)' : 无法从 'InIt (_cdecl *)(_InIt,iterator_traits<_iter>:: 转换参数 3差异类型)'到'多项式*' 1> 上下文不允许消除重载函数的歧义

在第二行,它说 newNode 再次未声明。

这里有什么问题? :( 我正在尝试将值放在链表中的结构中。在编码更多之后,我想在输入两个值时创建一个新的链表。

【问题讨论】:

  • 问题与链表无关。

标签: c++ class pointers


【解决方案1】:

您从未声明过next,而poly 是一个变量,而不是一个类型。应该是polynomial *poly,然后是poly = new polynomial(input1, input2, next);

【讨论】:

  • 大声笑,我是个白痴!哈哈哈,谢谢 Jorge,非常感谢您的帮助!
  • 发生在我们所有人身上。很高兴我能帮上忙。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多