on a fn call in c++, args are copied to the corresponding parameter. Is this initialization or assignment?

StackOverflow https://stackoverflow.com/questions/14737680

  •  07-03-2022
  •  | 
  •  

Pergunta

on a function call in c++, arguments are copied to the corresponding parameter. Is this initialization or assignment?

Foi útil?

Solução

Argument passing semantics are that of initialization. Meaning, your classes' copy/move constructors will be invoked.

Outras dicas

Then the arguments are by value they are copy-constructed (i.e. initialization).

Initialization: (please check the original-draft)

5.2.2 Function call

When a function is called, each parameter shall be initialized with its corresponding argument. [Such initializations are indeterminately sequenced with respect to each other] When a function is called, the parameters that have object type shall have completely-defined object type. [this still allows a parameter to be a pointer or reference to an incomplete class type. However, it prevents a passed-by-value parameter to have an incomplete class type.] During the initialization of a parameter, an implementation may avoid the construction of extra temporaries by combining the conversions on the associated argument and/or the construction of temporaries with the initialization of the parameter. The lifetime of a parameter ends when the function in which it is defined returns. The initialization and destruction of each parameter occurs within the context of the calling function. [the access of the constructor, conversion functions or destructor is checked at the point of call in the calling function. If a constructor or destructor for a function parameter throws an exception, the search for a handler starts in the scope of the calling function; in particular, if the function called has a function-try-block with a handler that could handle the exception, this handler is not considered.]

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top