Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!
What I'd do is the constructor way. After all the object is being constructed with this parameter. But you can do the operator on top of that and leave yourself the choice for later on. Would look like this on the example of the up msg:
With the conversion code inside the Up_GmCmd constructor ofc.
Another option would be having an update method of some sort with the cmd parameter. This way you can set it in the constructor, operator and when dealing with an object reference. Would save you runtime when you can get rid of the extra allocation. Unless you want to follow the C# like convention where new objects are returned by member methods. It does seem weird to me to do this in an operator though. These are usually used to update the object itself rather than return a new one.
is looking weird. It looks like I'm assigning the pointer of _open_guild_stage to _open_guild_stage. Which is definitely not what it's doing! It's taking the pointer and converting it, and that is not clear.
But to be honest, having both constructor + operator just seems wasteful on my time. After all I have to create ~70+ Classes for that thing. Even though it's not a huge amount of code, its alot when redoing it ~70 times. Since the class leaves CLR land as soon as possible!
What I mean by that is, that the class Up_GmCmd will only have "readonly" fields. So set on constructor and never modified. Since the only purpose of the CLR library is converting the C++ data structure from Protobuf to C# land because protobuf didn't support C# until v3, and the whole code depends on v2.
Since all conversion operators return new objects don't they? At least thats how I did it always. Remember I'm just talking about conversion here. Not other operators like == or /.
Since all conversion operators return new objects don't they? At least thats how I did it always. Remember I'm just talking about conversion here. Not other operators like == or /.
. These usually perform the assignment and return a self reference by C++ convention. I rarely see a "conversion operator" but they are practically assigning, aren't they?
I would recommend doing assignment operators like that in C++. If you still want to have a copy of the object, it's a lot more readable and clear to do it in two steps.
Code:
Object newObj = other;
This is where C++ style indeed differs from C# style where it's common to [STRIKE]waste memory[/STRIKE] create copies of the object on all conversions / changes.