传递我的参考 c++ 时使用类的公共函数时出错
Error in using class's public function when passed my reference c++
我试图为向量创建一个排序函数。这是我写的
struct Xgreater
{
bool operator()( const lineCommand& lx, const lineCommand& rx ) const {
return lx.getEndTime() < rx.getEndTime();
}
};
我的班级在哪里:
class lineCommand {
public:
lineCommand(float startTime, float endTime);
virtual ~lineCommand();
//those are short inline functions:
//setting the starting time of the command
void setStartTime(const float num){mStartTime=num;};
//setting the ending time of the command
void setEndTime(const float num){mEndTime=num;};
// returning the starting time of the command
float getStartTime(){return mStartTime;};
// returning the ending time of the command
float getEndTime(){return mEndTime;};
private:
float mStartTime;
float mEndTime;
};
不在xgreater中。我在eclipse中得到错误提示:
Invalid arguments '
Candidates are:
float getEndTime()
在:lx.getEndTime and rx.getEndTime
按如下方式声明函数
float getEndTime() const {return mEndTime;};
^^^^^
在这个操作符声明中
bool operator()( const lineCommand& lx, const lineCommand& rx ) const {
return lx.getEndTime() < rx.getEndTime();
}
参数lx
和rx
为常量引用。因此,只能使用这些引用调用带有限定符const的成员函数。
与声明函数getStartTime
float getStartTime() const {return mStartTime;};
相关文章:
- C++-试图将函数指针推回到另一个CPP文件中的矢量时出错
- 使用dynamic_cast和构造函数时出错
- CHECK(调用)函数在Google Colab中出错
- 从R调用C++函数并对其进行集成时出错
- 这个函数哪里出错了
- PrintWindow函数在notepad.exe中出错
- 使用运算符调用 void 函数时出错<set>
- 为 NewObjectA() 函数创建 jvalues 的参数数组时出错 - JNI Invocation API
- 在定义的函数中使用常量时出错
- 将成员函数作为构造函数参数调用时出错 "Variable is not a type name"
- 使用根/C++时出错:没有匹配的构造函数来初始化'TTree'
- Arduino IDE 中使用 strncmp 函数时出错
- 从DLL导出函数,LoadLibrary()需要用TEXT转换的字符串才能编译而不会出错
- 编译包含指向模板函数的指针的初始值设定项列表时,gcc 出错,但 clang 不出错
- 使用一个参数的模板函数时出错(适用于 2)
- 为什么 stl 字符串C++函数有时出错有时会出错?
- 使用类的构造函数时出错
- 在 c++ 的构造函数中分配对象向量时出错
- 为什么在函数参数前面添加 const 会出错?
- 调用析构函数时出错