没有找到函数定义?

Stu*_*860 0 c++ visual-c++ c++11

我正在尝试定义函数“getCurSize”,但由于某种原因,即使我在其下面定义它,它也无法识别该定义并以绿色下划线显示。(这里是初学者,请耐心等待)

template<class ItemType>
class FDHPolynomial
{
private:
    FDHNode<ItemType>* headPtr;
    int itemcount;
    FDHNode<ItemType>* getPointedTo(const ItemType& nodenum) const;

public:
    FDHPolynomial();
    FDHPolynomial(const FDHPolynomial <ItemType>& aPoly);
    virtual ~FDHPolynomial();

    int getCurSize() const;
    bool isEmpty() const;
    bool add(const ItemType& newCoeffi, const ItemType& newExpon);
    bool remove(const ItemType& anExpon);
    void clear();
    bool contains(const ItemType& aExpon) const;
    ItemType degree() const;
    ItemType coefficient(const ItemType& power) const;
    void changeCoefficient(const ItemType& newCoeffi, const ItemType&power);
    std::vector<ItemType> toVector() const;

void print();


};

template<class ItemType>
int Polynomial<ItemType>::getCurSize() const
{
    return itemCount;
}
Run Code Online (Sandbox Code Playgroud)

San*_*ela 5

您的作用域运算符 (::) 无法Polynomial<ItemType>::getCurSize() const与声明的任何函数匹配,因为Polynomial它不作为类存在。因为类FDHPolynomial有一个getCurSize() const函数,所以将定义更改为:

template<class ItemType>
int FDHPolynomial<ItemType>::getCurSize() const {
    return itemCount;
}
Run Code Online (Sandbox Code Playgroud)