Correct my if I'm wrong, but the reason you pass integers and other basic data types by value is because the memory they occupy is too small, so it's a waste to make a pointer variable of that data type (which will probably be at least the same size as the data type).
That's why I always pass int
s and other basic types by value to functions, and other (bigger) data types are passed by const references or by pointers of const. Did I grasp this right?
Now I've seen many APIs that pass enum
types as const references, like so:
enum FileOptions { ReadOnly, ReadWrite, WriteOnly };
void processFile(const FileOptions &options);
As far as I know, enums are usually interpreted by the compiler as plain integers, so why are they passed by references? Is it done to abstract the data type from the developer, so he won't think of FileOptions
as an integer? (although it is).