Hi, I'm writing a ray-tracer wherein one HitPoint object is passed between all the Intersectables in the scene. The Intersectables then store a pointer to themselves inside the HitPoint object. The issue I'm having is that the Intersectable->intersect(HitPoint) function is const, so the this pointer is a const Intersectable * const, and won't let me put it in the HitPoint object.
1) no, within a const function no member variables can be changed, but parameters can
2) yes, you can. please don't say things like this so confidently if you don't know because it misleads others. An Intersectable * const is a const pointer to an intersectable.
3) In the actual implementation it is initially set to NULL, but that has nothing to do with the issue.
Could you change HitPoint::intersectable to const Intersectable * to match the type of this? It's either that or casting this: (Intersectable * const)this
But really, I think intersect() should be a member of HitPoint:
it's not like I meant it in a mean way at all, it's just that as a programmer I'm constantly searching forums for info, and when I'm misled it costs me a lot of time and confusion, especially when guesses are said as a matter of fact.
That's the heart of the issue, really. I can't have HitPoint::intersectable be a const Intersectable * because then I couldn't change it. I need a variable pointer that points to a constant object. How would I say that in code, without making the member itself constant?
I can't I can cast away the const of the object by doing (Intersectable * const)(this), I get a C2166.
I've just been messing around with modifiers trying to get it to work, that's the latest incarnation.
I understand, but I need that to vary on the HitPoint object. Should I be trying to make HitPoint::intersectable a const Intersectable ** const and then being like *hitpoint.intersectable = this?