指针也许比引用更好~。~
这是Qt开发者网站的一片文章的节选,讲述API的设计原则的,里面有一段关于C++中需要修改实参的函数的参数是选择指针还是引用的区别。然后,Qt里面选择了指针。因为调用这种函数的时候可以让人一眼看出这个函数调用会修改实参的值。
原文章:http://developer.qt.nokia.com/wiki/API_Design_Principles
C++ Specifics
Value vs. Object
Pointers vs. References
Which is best for out-parameters, pointers or references?
void
getHsv(
int
*h,
int
*s,
int
*v)
const
void
getHsv(
int
&h,
int
&s,
int
&v)
const
Most C++ books recommend references whenever possible, according to the general perception that references are “safer and nicer” than pointers. In contrast, we at Qt Software tend to prefer pointers because they make the user code more readable. Compare:
color.getHsv(&h, &s, &v);
color.getHsv(h, s, v);
Only the first line makes it clear that there’s a high probability that h, s, and v will be modified by the function call.