Created
March 25, 2018 00:02
-
-
Save AustinBrunkhorst/402f85b21539250532da613ec02bd00f to your computer and use it in GitHub Desktop.
C++ Reflection | Functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct SoundEffect | |
{ | |
float volume; | |
void Load(const std::string &filename); | |
}; | |
int main(void) | |
{ | |
Type soundEffectType = typeof( SoundEffect ); | |
Field volumeField = soundEffectType.GetField( "volume" ); | |
// the runtime supports overloading, but by default returns the first overload | |
Method loadMethod = soundEffectType.GetMethod( "Load" ); | |
// creates an instance of a sound effect | |
Variant effect = soundEffectType.Create( ); | |
// effect.volume is now 85 | |
volumeField.SetValue( effect, 85.0f ); | |
// 85 | |
volumeField.GetValue( effect ); | |
// effect.Load is called | |
loadMethod.Invoke( effect, std::string { "Explosion.wav" } ); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment