You are here:

C++/function arguments

Advertisement


Question
 Hi Vijayan,


 i have designed two functions like

 void verify(Hvrbuffer *message)--> this will be work when  message is null or not null
 void verify(Hvrbuffer &message)--> this will work only when message is not null

 Can you please explain me in the above cases when i have to use pointer  and references as function arguments other than the above mentioned scenarios

 interms of memory allocation / deallocation and any  other value added services for each one of these ?

 thanks in advance,
     sireesh


Answer
In either case, memory for an object of type is not allocated Hvrbuffer is not allocated or deallocated when this function is called. Passing a pointer or a reference to an object does not create a copy of the object - they are equally efficient.

The only issue in question is: will the function always be called with a valid object? If yes, use a reference. If no, use a pointer (the pointer could be null).  

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


vijayan

Expertise

my primary areas of interest are generic and template metaprogramming, STL, algorithms, design patterns and c++11. i would not answer questions about gui and web programming.

Experience

about 15 years or so

Education/Credentials
post graduate engineer

©2016 About.com. All rights reserved.