开发者

Passing arguments by reference and address [duplicate]

开发者 https://www.devze.com 2023-01-30 02:25 出处:网络
This question already has answers here: Closed 12 years ago. Possible Duplicate: How to pass objects to functions in C++?
This question already has answers here: Closed 12 years ago.

Possible Duplicate:

How to pass objects to functions in C++?

When should I be passing arguments by reference and when p开发者_JAVA百科assed by address?

I mean Except the case of pass by const reference, is there any difference between the two.


I personally pass by pointer (address) when the pointer may be null, and pass by reference when it can't be null.

There are plenty of other considerations (const/non-const, smart/weak pointers etc) but I think this is a good guideline and answers your question well.

0

精彩评论

暂无评论...
验证码 换一张
取 消