科技公司网站设计公司,北京塞车网站建设,淘宝客cms网站建设,2003iis网站建设错误#include iostream using namespace std; class Coordinate { public: // 无参构造函数 // 如果创建一个类你没有写任何构造函数#xff0c;则系统自动生成默认的构造函数#xff0c;函数为空#xff0c;什么都不干 // 如果自己显示定义了一… #include iostream using namespace std; class Coordinate { public: // 无参构造函数 // 如果创建一个类你没有写任何构造函数则系统自动生成默认的构造函数函数为空什么都不干 // 如果自己显示定义了一个构造函数则不会调用系统的构造函数 Coordinate() { c_x 0; c_y 0; } // 一般构造函数 Coordinate(const std::string x, const std::string y):c_x(x), c_y(y){} //列表初始化 // 一般构造函数可以有多个创建对象时根据传入的参数不同调用不同的构造函数 Coordinate(const Coordinate c) { // 复制对象c中的数据成员 c_x c.c_x; c_y c.c_y; } // 等号运算符重载 Coordinate operator (const Coordinate rhs) { // 首先检测等号右边的是否就是等号左边的对象本身如果是直接返回即可 if(this rhs) return* this; // 复制等号右边的成员到左边的对象中 this-c_x rhs.c_x; this-c_y rhs.c_y; return* this; } std::string get_x() { return c_x; } std::string get_y() { return c_y; } private: std::string c_x; std::string c_y; }; int main() { Coordinate c3(1.0, 2.0); coutc3 (c3.get_x(), c3.get_y())endl; return 0; }