Reputation: 313
I have a template class called Heap. My problem is that I want to implement the insert function at the bottom. But I can't reach the member variable of the Values vector. When I write Values[hole/2].tall it can't reach it(tall variable does not come directly after writing the dot). So can anybody please explain this ?
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 )
{
}
}
}
Upvotes: 0
Views: 158
Reputation: 1736
This
for(int hole=currentSize; hole>1 && (value > Values[hole/2].tall)); hole/=2 )
contains a surplus round closing bracket; make it
for (int hole=currentSize; hole>1 && (value > Values[hole/2].tall); hole/=2)
Upvotes: 1