我正在尝试定义函数“ 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;
}
最佳答案
您的作用域运算符(::)无法将Polynomial<ItemType>::getCurSize() const
与声明的任何函数匹配,因为Polynomial
不作为类存在。由于类FDHPolynomial
具有getCurSize() const
函数,因此将您的定义更改为:
template<class ItemType>
int FDHPolynomial<ItemType>::getCurSize() const {
return itemCount;
}
关于c++ - 找不到功能定义?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43175893/