The Partridge Family were neither partridges nor a family. Discuss.
-
slavaxd
- Posts: 1
- Joined: January 26th, 2023, 1:35 pm
Post
by slavaxd » January 26th, 2023, 1:38 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?
-
LuisR14
- Posts: 1248
- Joined: May 23rd, 2013, 3:52 pm
- Location: USA
-
Contact:
Post
by LuisR14 » May 20th, 2023, 7:46 pm
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=irc://irc.freenode.net/#pchili]
irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]
alt[/url] -- join up if ever want real-time help or to just
chat --