C++中Argument和Parameter这两个词的含义

用中文讲就是在C++中,Argument指实参,Parameter指形参。


[ZZ]http://www.devx.com/tips/Tip/13049

Understanding the Difference Between an Argument and a Parameter

The words argument and parameter are often used interchangeably in the literature, although the C++ Standard makes a clear distinction between the two. An argument is one of the following: an expression in the comma-separated list in a function call; a sequence of one or more preprocessor tokens in the comma-separated list in a macro call; the operand of a throw-statement or an expression, type, or template-name in the comma-separated list in the angle brackets of a template instantiation. A parameter is one of the following: an object or reference that is declared in a function declaration or definition (or in the catch clause of an exception handler); an identifier between the parentheses immediately following the macro name in a macro definition; or a template-parameter. This example demonstrates the difference between a parameter and an argument:

void func(int n, char * pc); //n and pc are parameters
template <class T> class A {}; //T is a a parameter

int main()
{
  char c;
  char *p = &c;
  func(5, p); //5 and p are arguments
  A<long> a; //'long' is an argument
  A<char> another_a; //'char' is an argument
  return 0;
}

猜你喜欢

转载自blog.csdn.net/updog/article/details/6687529
今日推荐