Xfce
Foundation Classes |
|||
« Main Page | |||
Programming GuidelinesTable of ContentsCoding ConventionsXFC uses the GNU C++
coding
style, except for the following conventions:
References and PointersThere are two ways to pass an argument to a function, call-by-value and call-by-reference. Call-by-value copies an argument into the function parameter; modifying the parameter will have no affect on the argument. This is the default in both C and C++. Call-by-reference copies the address of an argument into the function parameter, not the argument; any modifications made to the parameter will affect the argument. In C you call-by-reference when you pass a pointer as an argument to a function. In C++ there are two ways to call-by-reference; you can either pass a pointer or a reference as an argument to a function. If it helps, you can think of a reference as behaving like a constant pointer but using a different notation and with several restrictions. A reference is declared by preceding the parameter name with the & operator, as in Gtk::Widget& widget. In contrast to pointers, XFC associates the & with the type name not the variable name.The restrictions on the use references are:
Function parameters and return valuesReferences and pointers are an integral part of C++ and XFC uses them frequently for specifying function parameters and return values. A non-copyable object is passed as a pointer if null is a valid value for the call-by-reference function parameter. If null is not a valid value the object is passed by reference. Copyable values such as built-in types, strings and vectors are passed as a const reference and returned by value.Signal classes are the only exception to this rule; their constructors take a pointer which cannot not be null. A reference is not used because it would conflict with the object class copy constructor.
|