class loc
{
private:
int longitude,latitude;
public:
loc();
loc(int lg,int lt)
{
longitude=lg;
latitude=lt;
}
void show()
{
cout<<longitude<<" ";
cout<<latitude<<"\n";
}
loc operator+(loc op2);
};
loc loc::operator+(loc op2)
{
loc temp;
temp.longitude=op2.longitude+longitude;
temp.latitude=op2.latitude+latitude;
return temp;
}
int main()
{
loc ob1(10,20),ob2(5,30);
ob1.show();
ob2.show();
ob1=ob1+ob2;
ob1.show();
return 0;
}
5 个解决方案
#1
#include "iostream.h"
class loc
{
private:
int longitude,latitude;
public:
loc(){};//look at here
loc(int lg,int lt)
{
longitude=lg;
latitude=lt;
}
void show()
{
cout<<longitude<<" ";
cout<<latitude<<"\n";
}
loc operator+(loc op2);
};
loc loc::operator+(loc op2)
{
loc temp;
temp.longitude=op2.longitude+longitude;
temp.latitude=op2.latitude+latitude;
return temp;
}
int main()
{
loc ob1(10,20),ob2(5,30);
ob1.show();
ob2.show();
ob1=ob1+ob2;
ob1.show();
return 0;
}
class loc
{
private:
int longitude,latitude;
public:
loc(){};//look at here
loc(int lg,int lt)
{
longitude=lg;
latitude=lt;
}
void show()
{
cout<<longitude<<" ";
cout<<latitude<<"\n";
}
loc operator+(loc op2);
};
loc loc::operator+(loc op2)
{
loc temp;
temp.longitude=op2.longitude+longitude;
temp.latitude=op2.latitude+latitude;
return temp;
}
int main()
{
loc ob1(10,20),ob2(5,30);
ob1.show();
ob2.show();
ob1=ob1+ob2;
ob1.show();
return 0;
}
#2
#include "iostream.h"
class loc
{
private:
int longitude,latitude;
public:
loc();//改为loc() {}
loc(int lg,int lt)
{
longitude=lg;
latitude=lt;
}
void show()
{
cout<<longitude<<" ";
cout<<latitude<<"\n";
}
loc operator+(loc op2);
};
loc loc::operator+(loc op2)
{
loc temp;
temp.longitude=op2.longitude+longitude;
temp.latitude=op2.latitude+latitude;
return temp;
}
int main()
{
loc ob1(10,20),ob2(5,30);
ob1.show();
ob2.show();
ob1=ob1+ob2;
ob1.show();
return 0;
}
class loc
{
private:
int longitude,latitude;
public:
loc();//改为loc() {}
loc(int lg,int lt)
{
longitude=lg;
latitude=lt;
}
void show()
{
cout<<longitude<<" ";
cout<<latitude<<"\n";
}
loc operator+(loc op2);
};
loc loc::operator+(loc op2)
{
loc temp;
temp.longitude=op2.longitude+longitude;
temp.latitude=op2.latitude+latitude;
return temp;
}
int main()
{
loc ob1(10,20),ob2(5,30);
ob1.show();
ob2.show();
ob1=ob1+ob2;
ob1.show();
return 0;
}
#3
loc();没有函数实现体
#4
应该loc operator+(loc op2);出错
她怎么可用loc op2参数定义
她怎么可用loc op2参数定义
#5
非常感谢
#1
#include "iostream.h"
class loc
{
private:
int longitude,latitude;
public:
loc(){};//look at here
loc(int lg,int lt)
{
longitude=lg;
latitude=lt;
}
void show()
{
cout<<longitude<<" ";
cout<<latitude<<"\n";
}
loc operator+(loc op2);
};
loc loc::operator+(loc op2)
{
loc temp;
temp.longitude=op2.longitude+longitude;
temp.latitude=op2.latitude+latitude;
return temp;
}
int main()
{
loc ob1(10,20),ob2(5,30);
ob1.show();
ob2.show();
ob1=ob1+ob2;
ob1.show();
return 0;
}
class loc
{
private:
int longitude,latitude;
public:
loc(){};//look at here
loc(int lg,int lt)
{
longitude=lg;
latitude=lt;
}
void show()
{
cout<<longitude<<" ";
cout<<latitude<<"\n";
}
loc operator+(loc op2);
};
loc loc::operator+(loc op2)
{
loc temp;
temp.longitude=op2.longitude+longitude;
temp.latitude=op2.latitude+latitude;
return temp;
}
int main()
{
loc ob1(10,20),ob2(5,30);
ob1.show();
ob2.show();
ob1=ob1+ob2;
ob1.show();
return 0;
}
#2
#include "iostream.h"
class loc
{
private:
int longitude,latitude;
public:
loc();//改为loc() {}
loc(int lg,int lt)
{
longitude=lg;
latitude=lt;
}
void show()
{
cout<<longitude<<" ";
cout<<latitude<<"\n";
}
loc operator+(loc op2);
};
loc loc::operator+(loc op2)
{
loc temp;
temp.longitude=op2.longitude+longitude;
temp.latitude=op2.latitude+latitude;
return temp;
}
int main()
{
loc ob1(10,20),ob2(5,30);
ob1.show();
ob2.show();
ob1=ob1+ob2;
ob1.show();
return 0;
}
class loc
{
private:
int longitude,latitude;
public:
loc();//改为loc() {}
loc(int lg,int lt)
{
longitude=lg;
latitude=lt;
}
void show()
{
cout<<longitude<<" ";
cout<<latitude<<"\n";
}
loc operator+(loc op2);
};
loc loc::operator+(loc op2)
{
loc temp;
temp.longitude=op2.longitude+longitude;
temp.latitude=op2.latitude+latitude;
return temp;
}
int main()
{
loc ob1(10,20),ob2(5,30);
ob1.show();
ob2.show();
ob1=ob1+ob2;
ob1.show();
return 0;
}
#3
loc();没有函数实现体
#4
应该loc operator+(loc op2);出错
她怎么可用loc op2参数定义
她怎么可用loc op2参数定义
#5
非常感谢