This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: compile or not compile


Hi Karol,

>...and something must be wrong when arguments are references because when I remove references program compiles fine.

Here's my C++ rule-of-thumb I've used since I started programming in C++:
For POD, ALWAYS pass-by-value and never pass-by-constant-reference.
For UDT, ALWAYS pass-by-constant-reference and never pass-by-value.
UNLESS, you need to modify the item, then pass-by-reference.
UNLESS, the item is optional, then pass-by-pointer (and NULL represents "optional parm not present").


Note: when I say "optional", I'm not necessarily referring to default value parameters.

Also note, pass-by-value can be pass-by-constant-value ... but I rarely do that.

POD is "plain old datatype", such as char, short, int, long, float, double, long double, bool, enum, pointer, function pointer.

UDT is "user defined types", such as classes, structs, unions.

HTH,
--Eljay


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]