Partager via


Function Call Operator: ()

A postfix-expression followed by the function-call operator, ( ), specifies a function call.

postfix-expression ( [argument-expression-list ] )

Remarks

The arguments to the function-call operator are zero or more expressions separated by commas — the actual arguments to the function.

The postfix-expression must evaluate to a function address (for example, a function identifier or the value of a function pointer), and argument-expression-list is a list of expressions (separated by commas) whose values (the arguments) are passed to the function. The argument-expression-list argument can be empty.

The postfix-expression must be of one of these types:

  • Function returning type T. An example declaration is

    T func( int i )
    
  • Pointer to a function returning type T. An example declaration is

    T (*func)( int i )
    
  • Reference to a function returning type T. An example declaration is

    T (&func)(int i)
    
  • Pointer-to-member function dereference returning type T. Example function calls are

    (pObject->*pmf)();
    (Object.*pmf)();
    

Example

The following example calls the standard library function strcat_s with three arguments:

// expre_Function_Call_Operator.cpp
// compile with: /EHsc

#include <iostream>
#include <string>

// STL name space
using namespace std;

int main()
{
    enum
    {
        sizeOfBuffer = 20
    };

    char s1[ sizeOfBuffer ] = "Welcome to ";
    char s2[ ] = "C++";

    strcat_s( s1, sizeOfBuffer, s2 );

    cout << s1 << endl;
}
Welcome to C++

See Also

Reference

Postfix Expressions

C++ Operators

Operator Precedence and Associativity

Function Declarations

Concepts

Function Call (C)

Change History

Date

History

Reason

June 2010

Fixed an error in the example description.

Customer feedback.