|It is actually the situation where you use a delegate.
It is very common on game servers which are doing things like guns/projectiles etc to do this. The reason is you want to bind a behaviour to a random class without worrying what the class is and going thru the issue you have. So when I have a bullet I don't care if it's a 50 cal, 45 magnum or a BB pellet it has a behaviour and I will execute the delegate function to move it and use the payload to hold a callback for the object to draw itself and vary the damage etc. The classes don't even have to be related to use a delegate they can have random relationships and it's safe.
So unlike a class/object a delegate is an action or an event and generally it carries a payload which can be other actions or objects. You called your function DoSomething and it goes to another object
The other cute thing is you can add and delete delegates at any time to an object and you can test for the presence of a delegate. So you can add/delete and turn on/off functionality to a class/object with ease without the class itself needing to know or building that functionality on all related classes.
All real game engines do it that way and typically your server connects to players etc via delegates. Usually it is just doing things like scoring etc and removing dead people etc so it doesn't care what the objects are it just needs a couple of things from them. The last thing you want the server doing is get involved heavily in the objects or you will bottleneck everything. When an object disconnects from the server it simply removes itself from the server multicast delegates and the server will no longer see it and it's free to delete itself or whatever in it's own good time. So typically a server doesn't get involved in creating or deleting objects either which is the responsibility of a spawn system(s).
Delegates | Unreal Engine[^]
Unity - Delegates[^](worth watching the video to see it's use in a game)
Unreal Engine has the classical layout (look at the block diagram at bottom) .. GameServer sits alone things only join
Gameplay Framework Quick Reference | Unreal Engine[^]
There are a number of articles on C/C++ delegates on this site and good old google will throw hundreds and obviously MS has a sample as Visual Studio has them.
delegate (C++ Component Extensions)[^]
You might also want to look at C++ Events which we sometimes use in place of a delegate
In vino veritas
modified 11-Jul-17 23:04pm.