Thursday 15 September 2011

C++ pass pointer by reference and assign default value -


I want to pass an indicator with reference to a function, such that I can actually change the address, passing Pointer indicator is

  canceling myFunc (some type * & var = zero);  

More definition:

  Zero MyClass :: myFunc (SomeType * and var) {if (var! = NULL) (* var) = (* SomeOtherPointer); If (some conditions) var = NULL; }  

Such a colt can decide whether he wants to call the function with an argument or without argument. And if he decides to pass a logic and holds some condition, then the passed indicator will then point to the tap

However - if I try to do so, then I It gets:

Error C2440: 'Default argument': 'Int' can not be explained for 'Type something' and '

!

The error message says this: You type a context-to-one-point-to-something Instead of passing an integer what you want to do, you can use a point-to-a-pointer-to-something type:

  Cancel myFunc (some type ** Var = NULL); Zero MyClass :: myFunc (some type ** var) {if (var! = NULL & var! = NULL) (** var) = (* SomeOtherPointer); If (var! = Null & amp; amp; amp; amp; some condition) * var = NULL; }  

No comments:

Post a Comment