Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In how many ways can a function be invoked(called) in C++?

Tags:

c++

function

I know of one way to call a function :

func(x, y);

Are there more ways to call a function?

like image 641
ayush Avatar asked Feb 24 '15 06:02

ayush


People also ask

How many ways can a function be invoked?

JavaScript functions can be invoked in four ways: as functions, as methods, as constructors, and.

What is invoking function in C?

When a function is invoked, you pass a value to the parameter. This value is referred to as actual parameter or argument. The parameter list refers to the type, order, and number of the parameters of a function. Parameters are optional; that is, a function may contain no parameters.

When a function is invoked in a program?

When a function gets invoked, we pass a value to the parameter. This value is known as an actual parameter or argument. The parameter list will refer to the type, order, and the number of the parameters of a function. Moreover, they are optional.


1 Answers

Functions can be invoked

  • explicitly, by providing an argument parenthesis after a designation of the function (in the case of constructors this is decidedly not formally correct wording, since they don't have names, but anyway),

  • implicitly, in particular destructors and default constructors, but also implicit type conversion,

  • via operators other than the function call operator (), in particular the copy assignment operator = and the dereferencing operator ->,

  • in a placement new expression, invocation of a specified allocation function by placing an argument parenthesis right after new (not sure if this counts as a separate way).

In addition library facilities can of course invoke functions for you.

I think the above list is exhaustive, but I'm not sure. I remember Andrei Alexandrescu enumerated the constructs that yielded callable thingies, in his Modern C++ Design book, and there was a surprise for me. So there is a possibility that the above is not exhaustive.

like image 197
Cheers and hth. - Alf Avatar answered Oct 04 '22 02:10

Cheers and hth. - Alf