I have used class overloads of operators many times before, including overloading operator=, however for some reason it is not building in this particular instance where I'm trying to convert from one object (struct CAirportNDB) to a class (class CAirport). I cannot see where the problem is myself, so any input as to what I'm doing wrong here (or suggestions as to how to do it better, noting that FindAirport() is a function that I don't really have control over) would be greatly appreciated!
Ah hah, thanks for catching that webJose! I'm sure I could add a constructor for this to reduce an operation, but changing the code to the following fixes the problem (separates construction and equation):
In regards to returning a const ref, it is being returned from a member function so I'm not entirely sure what you mean. Const ref is returned to allow operator= chaining.
I have seen that, but wouldn't that allow a left hand side variable in an equation chain to accidently screw up the right hand side (original) value? I know this is unlikely but I always make it a const just to be safe. You never know who is going to end up using your code!
No because operator='s right-hand side is traditionally const. True, someone might make a non-const version. But that is their loss, not yours, right? I mean, it is their program that will be damaged, not your library. But I guess const works just fine too.
And in any case, anyone really wanting to, could use const_cast to wave constness away.
I guess I might as well make it non-const just to go with standard convention, which of course if everyone would follow makes coding life much simpler. Thanks for pointing out my non-compliance with that, you are right if someone else goes against standard convention and messes it up that is their own problem!