【问题标题】:No members available for a vector of structs没有可用于结构向量的成员
【发布时间】: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


【解决方案1】:

这个

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)

【讨论】:

  • @gunescelli:这里不是“真正的”问题呢?这显然是您的代码中的语法错误。
  • 是的,你是对的。当模板类处于这样的位置时,Visual Studio 不会显示成员。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-25
  • 2012-12-27
  • 1970-01-01
  • 1970-01-01
  • 2013-11-20
相关资源
最近更新 更多