Express C ++ arguments using method interfaces

Is there a common way to express the use of arguments in C ++? I want to implicitly tell consumers of my class how the arguments they pass will be used by the class.

Examples:

  • I have my argument (clear it)
  • I will refer to your argument during my life (therefore you should NOT remove it while I am alive)
  • I will use your argument only at build time and will not contain a link

Is there a general way to express these things simply by using a method declaration? I think in the first case std :: auto_ptr makes sense. In the second case, I usually take a pointer to prevent someone from passing a value from the stack, which would quickly deprive my link, or, conversely, shared_ptr. In the third case, I take a link to allow values ​​from the stack.

How do you deal with this? Is it also necessary to rely on smart pointers here, or can such things be expressed simply using somehow links to bare links and pointers?

+5
source share
7 answers

Our team has similar coding agreements with those that you offer:

1 - auto_ptr , . ( .)

2 - shared_ptr , , , , , shared_ptr .

3 - , .

. , .

+6

, , , , , - . , , , , .

, , , . ( ) , ( ), -, .

, , , .

+3

, , , .

"" , (const).. ..

+2

, , , . , , , , .

, . , :)

( Java/Eclipse) , , - .

+2

, boost STL, , , ...

. ( , , - .) , , . ( 3.)

, , , . . ( 2.)

, , , , . undefined . (.. 2 3).

-const- , , , . , , - ! /, , const. = 2, = 3.

, 1 (callle ) ; , .

+2

, . .

Y.take_ZZZ(x)

x Y, x. ( Y x).

Y.own_ZZZ(x)

take; x Y, x , Y x ( , Y, , Y , , , Y). Y x , Y ( Y ).

Y.know_ZZZ(x)

/ x ( x), Y x. Y , x , .

x = Y.provide_ZZZ()

x - , Y. Y (&) , "" . , , Y , . x , , Y , , . x , Y. Y.done_with_ZZZ (x), Y, , x.

x = Y.give_ZZZ()

Y x . x .

x = Y.lend_ZZZ()

Y / x ( _ZZZ) Y . ( , Y X, x, (), , null.

x = Y.check_out_ZZZ() and Y.check_in_ZZZ(x)

Y x, .

x = Y.create_ZZZ()

Y x (factory).

, , , () .

+2

, - . , , .

, . , ( , , , ), , . ( , , , ), .

If you are in an environment where IntelliSense is available, make sure that the parameter description contains the necessary information. This can save you from any of these steps.

+1
source

All Articles