c++中的函数嵌套调用和嵌套定义问题

来源:互联网 发布:华为解锁码软件 编辑:程序博客网 时间:2024/06/04 18:45

c++中允许函数的嵌套调用,但不允许函数的嵌套定义,例如:

#include<iostream.h>
int SwpInt(int *a,int *b)
{
 int c;
 c=*a;
 *a=*b;
 *b=c;
 return a;
}
void main()
{
 int e=12;
 int f=89;
 SwpInt(&e,&f);
 cout<<e<<endl<<f<<endl;
}
这样定义是对的,但是如果如下定义就会出现编译错误:

#include<iostream.h>
void main()
{
 int e=12;
 int f=89;
 int SwpInt(int *a,int *b)
 {
  int c;
  c=*a;
  *a=*b;
  *b=c;
  return a;
 }
 SwpInt(&e,&f);
 cout<<e<<endl<<f<<endl;
}

error C2601: 'SwpInt' : local function definitions are illegal

0 0
原创粉丝点击