C++重载问题?
#include<iostream>usingnamespacestd;classnumber{public:intnum;munber(inta);intoperato...
#include<iostream>
using namespace std;
class number
{
public:
int num;
munber(int a);
int operator++();
};
number::munber(int a)
{
num=a;
}
int number:: operator++()
{
int t;
t=num++;
return t;
}
int main()
{
number n(10);
int c=n++;
cout<<c<<endl:
return 0;
}
出了什么问题呢?? 展开
using namespace std;
class number
{
public:
int num;
munber(int a);
int operator++();
};
number::munber(int a)
{
num=a;
}
int number:: operator++()
{
int t;
t=num++;
return t;
}
int main()
{
number n(10);
int c=n++;
cout<<c<<endl:
return 0;
}
出了什么问题呢?? 展开
1个回答
展开全部
#include<iostream>
using namespace std;
class over_loading
{
int x;
public:
over_loading()
{
x=0;
}
over_loading(int);
over_loading operator ++();
int get_x(){return x;}
};
over_loading::over_loading(int a)
{
x=a;
}
over_loading over_loading::operator ++() //这个是前置加要区别operator ++;
{
x++;
return *this;
}
int main()
{
int b;
cout<<"请输入一个输数,将进此运御行++重载森岩\n";
cin>>b;
over_loading c(b);
++c;
cout<<"\n重载后的数为:"<悄迅<c.get_x(); //get_x()得到x值
cin.get();
cin.get();
}
满意请采纳。
using namespace std;
class over_loading
{
int x;
public:
over_loading()
{
x=0;
}
over_loading(int);
over_loading operator ++();
int get_x(){return x;}
};
over_loading::over_loading(int a)
{
x=a;
}
over_loading over_loading::operator ++() //这个是前置加要区别operator ++;
{
x++;
return *this;
}
int main()
{
int b;
cout<<"请输入一个输数,将进此运御行++重载森岩\n";
cin>>b;
over_loading c(b);
++c;
cout<<"\n重载后的数为:"<悄迅<c.get_x(); //get_x()得到x值
cin.get();
cin.get();
}
满意请采纳。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询