我有一个名为Heap 的模板类。我的问题是我想在底部实现插入功能。但是我无法访问 Values vector 的成员变量。当我写 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)
关于c++ - 没有可用于结构 vector 的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34015941/