注册 登录
编程论坛 C++教室

请大家帮个忙

cjl730 发布于 2008-11-10 20:56, 1600 次点击
#include<iostream>
using namespace std;
int main()
{
   
   int swap(int *p1, int *p2);
   int a=1, b=2;
   swap(&a, &b);
   cout<<"a="<<a<<endl;
   return 0;
}
int swap(int *p1, int *p2)
{
   int temp;
   temp=*p1;
   *p1=*p2;
   *p2=temp;
}
这个为什么在vc++6.0中编译不了?
谢谢(在dev c++中编译成功)
11 回复
#2
kivcare2008-11-10 21:18
#include<iostream>
using namespace std;
int main()
{
   
   int a=1, b=2;
   swap(a,b);
   cout<<"a="<<a<<endl;
   return 0;
}
void swap(int *p1, int *p2)
{
   int temp;
   temp=*p1;
   *p1=*p2;
   *p2=temp;
}
#3
haitao8511212008-11-10 21:27
#include<iostream>
using namespace std;
int main()
{
   
   int a=1, b=2;
   swap(a,b);
   cout<<"a="<<a<<endl;
   return 0;
}
swap(int *p1, int *p2)
{
   int temp;
   temp=*p1;
   *p1=*p2;
   *p2=temp;
}
#4
newyj2008-11-10 21:42
把 函数声明放在 主函数 前
vc 对这个好象 有点 那什么
#5
zxwangyun2008-11-10 21:59
C++是一种强类型检查语言,所有变量或函数都必须先声明或定义后才能使用
#6
cjl7302008-11-11 12:02
回复 5# 的帖子
把程序详细的给我写一下好吗?
谢谢
#7
fresh_love2008-11-11 12:52
#include<iostream>
using namespace std;

int swap(int *p1, int *p2;//他的意思是:在主函数调用前先声明

int main()
{
   
   int swap(int *p1, int *p2);
   int a=1, b=2;
   swap(&a, &b);
   cout<<"a="<<a<<endl;
   return 0;
}

int swap(int *p1, int *p2)
{
   int temp;
   temp=*p1;
   *p1=*p2;
   *p2=temp;
}
#8
youhm2008-11-11 15:02
主要还是int swap函数没有返回值
#9
happytor2008-11-11 16:17
函数没有声明。
#10
tls4113232008-11-11 21:43
怎么没声明主函数的开头就是声明不过swap应该返回一个值
#11
scutdingyi2008-11-12 19:16
int swap(int *p1, int *p2)
{
   int temp;
   temp=*p1;
   *p1=*p2;
   *p2=temp;
return 0;
}
#12
啊明2008-11-13 12:40
#include<iostream>
using namespace std;

int swap(int *p1, int *p2);//他的意思是:在主函数调用前先声明

int main()
{
   
   int swap(int *p1, int *p2);
   int a=1, b=2;
   swap(&a, &b);
   cout<<"a="<<a<<endl;
   cout<<"b="<<b<<endl;
   return 0;
}

int swap(int *p1, int *p2)
{
   int temp;
   temp=*p1;
   *p1=*p2;
   *p2=temp;
   return temp;
}
 函数后面没有返回值,这个加了返回值可以用
1