在成员函数中对此的使用无效
Invalid use of this in member function
我的类中有一个方法how返回对对象的引用,但我不知道如何在这个方法中访问我的attribut。
Particule& update(double timestamp)
{
this->vx += timestamp;
}
vx
是我的对象Particule
的属性。但是,如果我尝试用this
访问vx
,我会出错,为什么?我以为这会奏效。
我的类定义:
#include <stdio.h>
#include <iostream>
class Particule{
public:
double rx, ry; //position
double vx, vy; //velocity
double fx, fy; //force
double mass; //mass
Particule ();
Particule(double rx, double ry, double vx, double vy, double fx, double fy, double mass);
Particule& update(double timestamp);
friend std::ostream& operator<<(std::ostream& str, Particule const& p)
{
return str <<
"rx : " << p.rx <<
" ry : " << p.ry <<
" vx : " << p.vx <<
" vy : " << p.vy <<
" mass : " << p.mass << 'n';
}
};
我不知道如何在我的方法更新中访问我的对象。我用object.update(timestamp);
调用此方法
如果定义在类之外,则必须执行以下操作:
Particule& Particule::update(double timestamp)
{
this->vx += timestamp;
return *this;
}
相关文章:
- C++无效使用非静态成员函数?
- 错误: 无效使用非静态数据成员"应用程序::应用程序构造函数"
- 指向成员的指针对托管类无效
- 在 stream_descriptor::async_wait 中无效使用非静态成员函数
- 对象分配-成员函数的使用无效错误
- C++ 在具有数组成员的类上无效指针/双精度释放
- 错误:无效使用非静态成员函数"int test::hotplug_callback(libusb_contex
- C++:易失性实例中的易失性成员函数 - 将数组分配给指针是无效的转换?
- 使用 vector.sort() 的非静态成员函数无效使用
- 设置类的枚举成员无效地使用"枚举"
- 无效使用非静态成员函数 c++ 线程 linux
- 无效使用非静态成员函数 int test::funcAB(int, int)
- 当使用嵌套类功能时,使用非静态数据成员的使用无效,但是当函数未固定时可以
- 错误:在 C++ 中无效使用非静态成员函数
- 在静态成员函数中无效使用成员“xx::x”
- C 11螺纹 - 非静态成员功能的使用无效 - 工作GCC 5.1.0损坏的GCC 7.3.1
- 将非静态成员函数C 的使用无效,而将成员功能作为函数变量
- 使用矢量指标对非静态数据成员的使用无效
- 错误:"指向成员的指针对托管类无效"
- 具有无效成员函数的模板类