Function Description

If I have fnc:

void fnc(const SomeType&){/**/}  

And when I list the preconditions and postconditions for this fnc, I think the enumeration of the form precondition is:
 SomeType should be of the correct type , pretty dumb, isn't it? I ask for this because in my uni they want us to list something like this, but if the type of the argument is not correct, the code will not compile in any case, so I consider it incorrect to provide this form. But, as usual, I'm wrong.

+3
source share
4 answers

Do not state the obvious.

As you say, the code will not explicitly compile if the types do not match.

- , .

+1

, , . .

, . , . :

  • ( c macro assert()), . .
  • static assertion ( std:: static_assert, ++ 0x BOOST_STATIC_ASSERT). , .
  • ( )

, .

0

, , , , .

, , , , ++. .

- , .

0
source

I would say the following:

The first argument must be of type SomeTypeor applicable to it.

Could the compiler check this. If some preconditions can be created from a function signature, this does not mean that these things are not prerequisites. After reading the prerequisites, the user should be able to write a program that will be correctly compiled and launched.

0
source

Source: https://habr.com/ru/post/1776197/


All Articles