【发布时间】:2015-12-01 08:35:05
【问题描述】:
我有一个名为 Heap 的模板类。我的问题是我想在底部实现插入功能。但我无法到达 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 )
{
}
}
}
【问题讨论】:
-
是编译错误还是只是IDE自动补全的问题,没有显示成员存在(“tall variable does not come directly after writing the dot”)?
-
其实我不记得错误了。现在我修复了一些。但在它给我一些错误之前,它无法从某物转换为某物。但现在它没有给出错误。但它仍然不会自动完成它。
标签: c++ class templates vector struct