从class_Type名称访问矢量值时不允许出现错误
Accessing vector values from a class_Type name not allowed error
我将无符号值存储在一个向量中,需要在另一个类中使用这些值。当我试图在函数中返回向量值时会出错,我不知道我做错了什么!这是我的部分代码:
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;
};
感谢您的帮助
TimeVector
是一个类型名。你把它当作一个变量来使用。这就像说
int == 42;
你需要一个变量:
int i = 3;
i == 42;
您可能想要的是在类中返回TimeVector
的实例:
typedef vector<unsigned> TimeVector;
const vector<unsigned> & get() const{return m_tv;)
相关文章:
- 错误:在第 6 行'{'标记之前,此处不允许使用函数定义
- C++错误:此上下文中不允许使用分解声明
- 内建数组出现不允许的类型不完整错误
- 数组错误(不允许类型不完整)
- 错误消息:不允许抽象类类型 "X" 的对象:纯虚拟"Y"没有覆盖器
- 错误:不允许使用抽象类类型的对象
- 网站组装 |错误:'C/ObjC'不允许使用无效'-std=c++11'参数
- 不允许调用 gil 要求函数,否则 gil 编译错误与 C++
- 我在代码中有一个错误,错误是:(智能感知:不允许抽象类类型"HourlyWorker"的对象:)
- 不允许使用错误类型
- 奇怪的不完整类型不允许错误
- Arduino / esp8266:错误:'Pchr 不允许部分属性
- 错误 - 此处不允许在 { 令牌之前使用函数定义
- 模板函数调用中C++错误:不允许使用类型名称
- 虚幻引擎 4.18.0,VS2017,不允许指向不完整类类型的错误指针
- 不允许向量<auto>吗?(错误:"自动"的使用无效)
- C++ 错误 - <unnamed-tag>不允许匿名联合的成员使用 cass 内初始值设定项
- 错误 C2491:不允许定义 dllimport 函数
- 不完整的类型不允许错误
- 类型不完整不允许错误,如何修复