The Partridge Family were neither partridges nor a family. Discuss.
- Posts: 1
- Joined: January 26th, 2023, 1:35 pm
In the series the ZBuffer class has an overload for the At method:
Code: Select all
float& At(int x, int y)
assert(x >= 0);
assert(x < width);
assert(y >= 0);
assert(y < height);
return pBuffer[y * width + x];
const float& At(int x, int y) const
return const_cast<ZBuffer*>(this)->At(x, y);
My question is why is it using const_cast<Zbuffer> rather than const_cast<float*>? I mean, the point of this is to return a CONST reference to the pbuffer amiright?
- Posts: 1248
- Joined: May 23rd, 2013, 3:52 pm
- Location: USA
the point is to remove the constness of the this pointer to be able to invoke its non-const At method (it expects/needs to work with a non-const ZBuffer)
edit: (forgot to include)
without the cast, it would become a recursive call to the function itself (instead of calling that non-const method)
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
[/url] -- join up if ever want real-time help or to just chat