没有可用于结构向量的成员

No members available for a vector of structs

本文关键字:向量 成员 结构 用于      更新时间:2023-10-16

我有一个名为Heap的模板类。我的问题是,我想在底部实现insert函数。但是我无法到达Values向量的成员变量。当我写Values[hole/2].tall时,它无法到达它(tall变量不会直接出现在写点之后)。有人能解释一下吗?

template <class Comparable>
class Heap
{
...
private:
// I have this vector
vector <heightNode <Comparable>> Values
};
template <typename Comparable>
struct heightNode
{
    Comparable tall;
    Comparable label;
    heightNode(const Comparable & t = Comparable(), const Comparable & la = Comparable()): tall(t),label(la) {}
    heightNode(const heightNode & rhs): tall(rhs.tall),label(rhs.label){}
};

template <class Comparable>
void Heap <Comparable>:: insert (const Comparable & value, const int & label)
{
    if(isFull())
    {
        cout <<"Heap is Full";
    }
    else
    {
        ++currentSize;//hole is an index we will put it to the last point in the vector.
        for(int hole=currentSize; hole>1 && (value > Values[hole/2].tall)); hole/=2 )
        {
        }
    }
}

for(int hole=currentSize; hole>1 && (value > Values[hole/2].tall)); hole/=2 )

包含一个多余的圆形闭合支架;使其成为

for (int hole=currentSize; hole>1 && (value > Values[hole/2].tall); hole/=2)