Consider the following piece of code (adapted from a real-world bug):
|
|
This function will work most of the time, but every now and again it will run across a directory which it will claim isn’t one. Why?
Read more...Consider the following piece of code (adapted from a real-world bug):
|
|
This function will work most of the time, but every now and again it will run across a directory which it will claim isn’t one. Why?
Read more...This is a style issue, so there is no right or wrong, but I suggest using a const reference for an input-only paramater to a C++ function and a pointer for an input/output or output-only parameter. This makes it slightly more obvious that the parameter might be modified by the function.
Example:
|
|
If my experience is typical, this is a very common construct:
|
|
The problem with this construct is that you have forced a container choice upon the user of your function. Slightly better, and basically your only choice when interoping with C, is this:
Read more...I’ve seen the following STL construct countless times:
|
|
Unless otherwise necessary, it is better to use an STL iterator because it enables you to more easily change the underlying container. You can isolate the code changes required to one line by using typedef
, as in: