Is it possible to use FName for a switch in C++?
If so, how do you call it? At the moment I'm trying;
asked Nov 06 '14 at 12:01 PM in C++ Programming
No, C++ does not have allow a mechanism for 'overloading switch' for your own types and, even then, case statements cannot use runtime values.
answered Nov 06 '14 at 12:19 PM
Steve Robb STAFF
I surprised UE4 doesn't already have this, considering all the pre-gen steps that already exist - but if you need to roll this yourself, try creating a macro that uses the same crc value.
code would look like:
The macro itself would compile out to just the constant number to make the valid switch statement. Use a separate tool that parses the file for the above macro, and replaces the number with the crc calculation based on the FName's own crc code (they would obviously need to be the same number).
You can choose to run the tool every compile, on demand (ie during new development), as a pre-checkin script, etc.
This could be useful for other situations than just switch statements, too.
answered Oct 29 '15 at 05:44 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here