C++错误..高手请教
来源:百度知道 编辑:UC知道 时间:2024/05/23 22:53:25
哪个高手帮忙给我看看..
我C++菜鸟~
#include<iostream>
using namespace std;
class compare{
int dif_a,dif_b;
public:
void Get(int a,int b);
void change(int a,int b);
void Print();
};
void Get(int a,int b)
{
dif_a=a;
dif_b=b;
}
void change(int a,int b){
int temp;
temp=a;a=b;b=team;
}
void Print()
{
cout<<"转换后的2个数为:"<<dif_a<<dif_b<<endl;
}
int main(){
int a,b;
compare d;
cout<<"请输入2个不同的数:";
cin>>a>>b;
d.Get(a,b);
d.change(a,b);
d.Print();
return 0;
}
错误描述是:error C2065: 'dif_a' : undeclared identifiererror C2065: 'dif_b' : undeclared identifier
error C2065: 'team' : undeclared identifier
我C++菜鸟~
#include<iostream>
using namespace std;
class compare{
int dif_a,dif_b;
public:
void Get(int a,int b);
void change(int a,int b);
void Print();
};
void Get(int a,int b)
{
dif_a=a;
dif_b=b;
}
void change(int a,int b){
int temp;
temp=a;a=b;b=team;
}
void Print()
{
cout<<"转换后的2个数为:"<<dif_a<<dif_b<<endl;
}
int main(){
int a,b;
compare d;
cout<<"请输入2个不同的数:";
cin>>a>>b;
d.Get(a,b);
d.change(a,b);
d.Print();
return 0;
}
错误描述是:error C2065: 'dif_a' : undeclared identifiererror C2065: 'dif_b' : undeclared identifier
error C2065: 'team' : undeclared identifier
#include<iostream>
using namespace std;
class compare{
int dif_a,dif_b;
public:
void Get(int a,int b);
void change(int a,int b);
void Print();
};
void compare::Get(int a,int b)//这里是没写类域说明符,下同
{
dif_a=a;
dif_b=b;
}
void compare::change(int a,int b){
int temp;
temp=a;a=b;b=temp;//这里是写错了
}
void compare::Print()
{
cout<<"转换后的2个数为:"<<dif_a<<dif_b<<endl;
}
int main(){
int a,b;
compare d;
cout<<"请输入2个不同的数:";
cin>>a>>b;
d.Get(a,b);
d.change(a,b);
d.Print();
return 0;
}
ps:你的Change函数有问题,没有用的
建议修改为
#include<iostream>
using namespace std;
class compare{
int dif_a,dif_b;
public:
void Get(int a,int b);
void c