I have a class which looks approximately like this:
class MeshClass
{
public:
Anchor getAnchorPoint(x, y)
{
return Anchor( this, x, y );
}
private:
points[x*y];
}
I want to make another class which represents an “Anchor” point which can get access to the Mesh and modify the point, like this:
class Anchor
{
public:
Anchor(&MeshClass, x, y)
moveAnchor(x, y);
}
The problem is when I try to make the Anchor in the MeshClass::getAnchorPoint method, something like return Anchor(this, x, y) but because this is const I can’t. As a workaround until I get this figured out I have Anchor accepting a reference to the point and moveAnchor moves the point directly.
Edit: The problem was most likely something dumb I was doing with trying to use a Reference. I changed to using a pointer like I normally would and I can pass in this with no complaints from the compiler. I’m almost certain I was getting an error related to this being const, but I can’t recreate it so I must just be out of my mind.
In C++, this is a pointer, not a reference. You could do something like this: