0

我将无符号值存储在一个向量中,我需要在另一个类中使用这些值。尝试在函数中返回向量值时出现错误,我不知道自己做错了什么!这是我的代码的一部分:

class Rider
{
  friend istream &operator>>(istream &in, Rider &rhs);

public:
  Rider(const string &name = ""): m_name(name){}

  const string &name() const {return m_name;}
  const string &team() const {return m_team;}
  const string &country() const {return m_country;}
  //const unsigned &numOfSatges() const {return m_tv;}

  typedef vector<unsigned> TimeVector;
  const vector<unsigned> & get() const{return TimeVector;) //Error: Type Name is not allowed!

private:

  string m_name;
  string m_team;
  string m_country;

  //unsigned m_numOfStages;

  TimeVector m_tv;

};

这是我试图访问存储在向量中的无符号值的地方:

class Match_Stage : public unary_function<const Rider&, bool>
{
public:
  Match_Stage(const unsigned stage) : m_stage(stage){}
  bool operator()( const Rider &rider) const
  {
    return rider.TimeVector == m_stage; //Error: Type Name is not allowed!
  }

private:
   unsigned m_stage;
};

感谢您的任何帮助

4

1 回答 1

1

TimeVector是一个类型名。您正在使用它,就好像它是一个变量一样。这就像说

int == 42;

你需要一个变量:

int i = 3;
i == 42;

您可能想要的是TimeVector在您的类中返回一个实例:

typedef vector<unsigned> TimeVector;
const vector<unsigned> & get() const{return m_tv;)
于 2013-08-04T07:57:32.807 回答