# 函式呼叫運算子：()

Visual Studio 2015

## 語法

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

```

## 備註

postfix-expression 必須評估為函式位址 (例如，函式識別項或函式指標的值)，而 argument-expression-list 是運算式的清單 (以逗號分隔)，其值 (「引數」) 會傳遞至函式。 argument-expression-list 引數可以是空的。

postfix-expression 必須是下列其中一種類型：

• 傳回類型 `T` 的函式。 如以下範例宣告所示

```T func( int i )

```
• 傳回類型 `T` 之函式的指標。 如以下範例宣告所示

```T (*func)( int i )

```
• 傳回類型 `T` 之函式的參考。 如以下範例宣告所示

```T (&func)(int i)

```
• 傳回類型 `T` 的成員指標函式取值 (Dereference)。 函式呼叫的範例如下

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

```

## 範例

```// 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++

## 函式呼叫結果

```// expre_Function_Call_Results.cpp
// compile with: /EHsc
#include <iostream>
class Point
{
public:
// Define "accessor" functions as
// reference types.
unsigned& x() { return _x; }
unsigned& y() { return _y; }
private:
unsigned _x;
unsigned _y;
};

using namespace std;
int main()
{
Point ThePoint;

ThePoint.x() = 7;           // Use x() as an l-value.
unsigned y = ThePoint.y();  // Use y() as an r-value.

// Use x() and y() as r-values.
cout << "x = " << ThePoint.x() << "\n"
<< "y = " << ThePoint.y() << "\n";
}

```

```// expre_Function_Results2.cpp
class A {
public:
A() {}
A(int i) {}
int SetA( int i ) {
return (I = i);
}

int GetA() {
return I;
}

private:
int I;
};

A func1() {
A a = 0;
return a;
}

A* func2() {
A *a = new A();
return a;
}

A& func3() {
A *a = new A();
A &b = *a;
return b;
}

int main() {
int iResult = func1().GetA();
func2()->SetA( 3 );
func3().SetA( 7 );
}

```