Would this essentially be the equivalency of the try: method in python? There are clearly differences, but trying to compare it to something I am somewhat familiar with already.
Basically, a failsafe to, “try this, if it fails, give error message”.
Would this essentially be the equivalency of the try: method in python? There are clearly differences, but trying to compare it to something I am somewhat familiar with already.
Basically, a failsafe to, “try this, if it fails, give error message”.
Not really, C++ has exceptions try
/catch
i.e.
#include <exception>
#include <print>
#include <vector>
int main()
{
std::vector vec{1, 2, 3, 4};
try
{
int value = vec.at(4);
std::println("value = {}", value);
}
catch (const std::exception& ex)
{
std::println("what(): {}", ex.what());
}
}
With that said, Unreal disables exceptions.
Are you talking about dynamic casting? Because I’m not quite sure how virtual functions are similar to exceptions. Virtual functions allow for “dynamic dispatch”.
Given a base class pointer or reference calling a virtual function will dispatch to the most derived version of the actual object being pointed/referenced to.
Example: Compiler Explorer
Using override just seemed like an easy way to run a try block without actually needing a try black in this scenario.
He didn’t need to use override in the function for it to work, but by adding it, then making a typo in the function name, resulted in a useful error callback. Whereas without override, it just gave the incorrect output.
It just seemed like a really simple try block, specifically for Dynamic Dispatch.
If you’re talking about the override
specifically (and not just virtual functions) then its essentially an opt-in syntax error checker.
The override
specifier was only added to the language in C++11, making it required for overriding virtual functions would break a lot of existing code. If the language was created today it would almost certainly be mandatory.
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.