上一页 1 ··· 44 45 46 47 48 49 50 51 52 ··· 60 下一页

2016年6月29日

C++ 类的继承三(继承中的构造与析构)

摘要: //继承中的构造与析构 #include using namespace std; /* 继承中的构造析构调用原则 1.子类对象在创建时会首先调用父类的构造函数 2.父类构造函数执行结束后,执行子类的构造函数 3.当父类的构造函数有参数时,需要在子类的初始化列表中显示调用 4.析构函数调用的先后顺序与构造函数相反 继承与其他类做成员变量混搭的情况下,构造和析构调用原则 1.先构造父类,在构造... 阅读全文

posted @ 2016-06-29 22:15 寒魔影 阅读(496) 评论(0) 推荐(0)

C++ 类的继承二(赋值兼容性原则)

摘要: //赋值兼容性原则 #include using namespace std; class PointA{ public: PointA(){ x = 0; y = 0; } void Set(){ } private: int x; int y; }; class PointB :public PointA{... 阅读全文

posted @ 2016-06-29 21:37 寒魔影 阅读(1004) 评论(0) 推荐(0)

C++ 类的继承一(访问控制)

摘要: //类的继承 #include using namespace std; /* 面向对象中的继承类之间的父子关系 1.子类拥有父类所有的成员属性和成员函数(包括私有成员变量) 2.子类就是一种特殊的父类 3.子类对象可以当作父类对象使用 4.子类可以拥有父类没有的方法和属性 c++中的类成员访问级别(public,protected,private) 类成员访问级别设置原则 1.需要被外界... 阅读全文

posted @ 2016-06-29 20:46 寒魔影 阅读(4806) 评论(0) 推荐(1)

C++ 匿名对象产生场景

摘要: //匿名对象产生的三种场景 #include using namespace std; class Point{ public: Point(int a,int b){ cout x = a; this->y = b; } Point(Point &a1){ cout x = a1.x; this->y =... 阅读全文

posted @ 2016-06-29 10:37 寒魔影 阅读(1216) 评论(0) 推荐(0)

2016年6月28日

C++ 类中的const关键字

摘要: //类中的const关键字 #include using namespace std; class Point{ public: //这个const关键字本质上修饰的是this指针 int GetX() const //====>int GetX(const this) { //因为this被隐藏,所以const关键字只好写在函数后面 /... 阅读全文

posted @ 2016-06-28 21:49 寒魔影 阅读(214) 评论(0) 推荐(0)

C++ 运算符重载四(自定义数组类)

摘要: //自定义数组类 #include using namespace std; //分析:能获取数组长度,添加元素,删除元素,修改元素 //要求重载[],=,==,!=运算符 class MyArray { private: int mLength; int* mSpace; public: MyArray(int length){ cout (mLe... 阅读全文

posted @ 2016-06-28 21:29 寒魔影 阅读(1007) 评论(0) 推荐(0)

2016年6月27日

C++ 运算符重载三(链式编程)

摘要: //运算符重载之链式编程 #include using namespace std; //对于友元函数重载运算符只适用于左操作数是系统变量的场景 //因为成员无法在系统变量中添加类成员函数,只能靠全局函数来实现 //链式编程的本质是:函数返回值当左值 class Point { public: //注意友元函数中,返回值不同,友元函数就会不同,跟函数重载有区别 friend o... 阅读全文

posted @ 2016-06-27 16:25 寒魔影 阅读(833) 评论(0) 推荐(0)

C++ 运算符重载二(一元运算符重载)

摘要: //一元运算符重载 #include using namespace std; class Point { public: Point(int x,int y){ this->x = x; this->y = y; } Point(Point &p){ this->x = p.x; this->y = p.... 阅读全文

posted @ 2016-06-27 11:32 寒魔影 阅读(1375) 评论(0) 推荐(0)

C++ 运算符重载一(二元运算符重载)

摘要: //二元运算符重载 #include using namespace std; class Point { public: Point(int x,int y){ this->x = x; this->y = y; } //为什么要使用友元函数呢 friend Point operator+(Point &p1, Point &p... 阅读全文

posted @ 2016-06-27 10:26 寒魔影 阅读(1413) 评论(0) 推荐(0)

2016年6月24日

C++ 友元类,友元函数

摘要: //友元函数 友元类 #include using namespace std; class PointB { public: friend class PointC; //类PointC是类PointB的友元类--意味着类PointC对象可以调用PointB中所有的成员 void Test(){ ; } private: int ... 阅读全文

posted @ 2016-06-24 09:59 寒魔影 阅读(208) 评论(0) 推荐(0)

上一页 1 ··· 44 45 46 47 48 49 50 51 52 ··· 60 下一页

导航