Possible Duplicate:
FAQ: How to pass objects to functions in C++?
Pointer vs. Reference
Hi all,
in c/c++,
we can pass a object as call by reference or passing pointer of the object.
for example:
i want to create a function which will take string vector as input and output a map that contains some value for each string. the return value of the function is bool, which indicate success or failure.
函数(通过引用调用)
bool calculateSomeValue( vector<string> input, map<string, double>& result) { //// bla bla bla return true/false; }
函数(使用指针)
bool calculateSomeValue( vector<string> input, map<string, double>* result) { //// bla bla bla return true/false; }
哪一个最好?有人知道这两种选择的利弊吗?
提前谢谢。