Besides what @Erik said about the return type, a little digression on this-pointer:
The following is equivalent:
struct my_struct{
my_struct* get_this() const { return this; }
};
my_struct obj;
my_struct* obj_this = ob.get_this();
std::cout << std::boolalpha;
std::cout << "&obj == obj_this = " << &obj == obj_this << "\n";
A pointer thisis just a pointer to this object, you can consider it hidden. This is more understandable in C:
typedef struct my_struct{
int data;
typedef void (*my_struct_funcptr)(struct my_struct*,int);
my_struct_funcptr func;
}my_struct;
void my_struct_func(my_struct* this, int n){
this->data += n;
}
my_struct obj;
obj.data = 55;
obj.func = &my_struct_func;
obj.func(&obj, 15);
std::cout << obj.data;
source
share