输出结果总是是1234,如果想输出1321 samsung message send,应该怎么改动啊,
只改动这一部分的代码
Mobile::Mobile(){}
Mobile::Mobile(char *t,int c, int n):Telephone(n)
{
strcpy(type,t);
cost = c;
}
int operator<(Mobile &x1, Mobile &x2)
{
if(x1.number < x2. number) return x2.number;
else return x1.number;
}
源程序如下:
/*程序运行结果为:
1321 samsung message send*/
#include<string.h>
//StudybarCommentBegin
#include<iostream>
using namespace std;
//#include <iostream.h>
class Telephone
{
protected :
int number;
public:
Telephone()
{number=1234;}
Telephone(int n)
{number=n;}
void showNumber()
{cout<<"my phone number is: "<<number<<endl;}
void call()
{cout<<"the phone is calling \n";}
};
class Mobile:public Telephone
{
char *type = new char[20];
int cost;
public:
Mobile();
Mobile(char *t,int c, int n); //n-tel,c-cost,t-type
void message()
{
cout<<number<<"\t"<<type<<"\tmessage send\n ";
}
friend int operator<(Mobile &x1,Mobile &x2);
};
//StudybarCommentEnd
Mobile::Mobile(){}
Mobile::Mobile(char *t,int c, int n):Telephone(n)
{
strcpy(type,t);
cost = c;
}
int operator<(Mobile &x1, Mobile &x2)
{
if(x1.number < x2. number) return x2.number;
else return x1.number;
}
//StudybarCommentBegin
int main()
{
Mobile m1;
Mobile m2("samsung",3500,1321);
if(m1<m2)
m1.message();
else
m2.message();
}
//StudybarCommentEnd