转换错误? (即'!='没有转换FDHPolynomial从' nullptr'到' int')

时间:2017-04-03 05:04:58

标签: c++ c++11 visual-c++

我正在制作这个添加函数定义,但我不断收到这些转换错误,我认为我调用了一个类或函数错误,但我真的不明白或者找不到导致错误的原因。 (抱歉长功能,我试图将其删除)

template<class ItemType>
bool FDHPolynomial<ItemType>::add(const ItemType& newCoefficient, const   ItemType& newExponent)
{
if (newCoefficient == 0)//not wasting memory to store 0
{
    return false;//no node added
}
else if (isEmpty())//if this is the first node added
{
    FDHNode<ItemType>* newNodePtr = new FDHNode<ItemType>();//create new node
    newNodePtr->setCoeffi(newCoefficient);//set contents
    newNodePtr->setExpon(newExponent);
    newNodePtr->setNext(nullptr);//since this is the only node, next value is nullptr

    headPtr = newNodePtr;//first node is the head node

    itemCount++;
}
else if (contains(newExponent))//if a node of this degree exists, add to its exponent
{
    FDHNode<ItemType>* nodeToModifyPtr = getPointedTo(newExponent);//find the existing node
    ItemType sumCoefficient = newCoefficient + nodeToModifyPtr->getCoeffi();//add new coefficient to existing coefficient

    if (sumCoefficient == 0)//if added value cancels out a value
    {
        remove(newExponent);
    }
    else
    {
        nodeToModifyPtr->setCoeffi(sumCoefficient);//apply sum of coefficients
    }

    //itemCount does not increment
}
else if (newExponent > degree())//if new exponent is greater than any existing exponents
{
    FDHNode<ItemType>* newNodePtr = new FDHNode<ItemType>();//create new node
    newNodePtr->setCoeffi(newCoefficient);//set contents
    newNodePtr->setExpon(newExponent);

    newNodePtr->setNext(headPtr);//place at front of the chain

    headPtr = newNodePtr;//new node is now the head node

    itemCount++;
}
else//if new node needs to be inserted somewhere after the head node
{
    FDHNode<ItemType>* newNodePtr = new FDHNode<ItemType>();//create new node
    newNodePtr->setCoeffi(newCoefficient);//set contents
    newNodePtr->setExpon(newExponent);

    FDHNode<ItemType>* curPtr = headPtr;//this pointer will cycle through       nodes until either a node with a degree smaller than newExponent is found or the last node is reached

    while ((curPtr->getExpon() > newExponent) && (curPtr->getNext() != nullptr))
    {
        curPtr = curPtr->getNext();//advance curPtr
    }

0 个答案:

没有答案