摘要: #include "stdafx.h" #include #include #include using namespace std; class CSelsctLesson { public: CSelsctLesson(); CSelsctLesson( string lesson ) { LessonName = lesson;... 阅读全文
posted @ 2016-05-31 02:01 01Turing 阅读(671) 评论(0) 推荐(0) 编辑
摘要: #include "stdafx.h" #include using namespace std; class Term { public: const int x; Term( int c); }; /* Term::Term(int c) { x = c; //错误,不能采用在构造函数中对常数据成员赋初值的方法进行初始化 } */ Term::Term(in... 阅读全文
posted @ 2016-05-30 10:15 01Turing 阅读(1483) 评论(0) 推荐(0) 编辑
摘要: // this.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include using namespace std; class A { public: A() { i = 0; } void add() { i++;} A*sp() { return this; } int Is(A*s) { return s->i; } private: i... 阅读全文
posted @ 2016-05-28 15:35 01Turing 阅读(183) 评论(0) 推荐(0) 编辑
摘要: 有一个点类point,具有两个实数坐标,希望主程序使用这个类完成一下功能: 1.主程序为类point申请10个连续的存储空间 2.调用一个函数Set()从键盘输入10个对象的属性,并顺序存入申请的内存中 3.调用一个函数Display()显示10个对象的值 4.调用一个函数Length(),计算将这些点连成一条折线时,这条折线的长度 5.程序结束时,删除申请的内存 6.演示析构函数(动态对象或堆对... 阅读全文
posted @ 2016-05-27 14:57 01Turing 阅读(479) 评论(0) 推荐(0) 编辑
摘要: #include "stdafx.h"#includeusing namespace std;class Box{ int height; int width; int length;public: Box(); Box(int h, int w, int l) :height(h), width(w), length(l) {} int volume(); ... 阅读全文
posted @ 2016-05-26 15:22 01Turing 阅读(152) 评论(0) 推荐(0) 编辑
摘要: // 对象指针.cpp : 定义控制台应用程序的入口点。// #include "stdafx.h"#includeusing namespace std;class Student{ int id; char name[10]; float score;public: Student(int pid, char *pname, float s); void disp... 阅读全文
posted @ 2016-05-26 13:44 01Turing 阅读(105) 评论(0) 推荐(0) 编辑
摘要: // 队列操作类.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include using namespace std; struct list { int data; list *next; }; class Queue { public: Queue() { ... 阅读全文
posted @ 2016-05-26 05:02 01Turing 阅读(111) 评论(0) 推荐(0) 编辑
摘要: //如果不显示定义复制构造函数,编译会出错,原因是:在创建对象s2时,调用默认复制构造函数并用对象s1对其进行初始化,致使s2中指针 //与s1中指针指向同一储存空间,当一个对象生命周期结束后调用析构函数释放内存空间后,另一个变量的指针悬空,无法正常使用。 //浅复制 //再用一个对象初始化另一个对象时,只复制了成员,没有复制资源(指堆内存 ,数据成员没有具体值),使两个对象同时指向同一资源, /... 阅读全文
posted @ 2016-05-26 03:10 01Turing 阅读(222) 评论(0) 推荐(0) 编辑
摘要: // 对象做函数参数和返回值.cpp : 定义控制台应用程序的入口点。//exit(0)表示正常退出程序,exit(0)表示异常退出 //在调用input时,编译器用对象A去创建了形参对象temp,调用了复制构造函数,对象A中的数据复制给了对象temp// 在input函数中,执行temp.set(s),为对象temp中数据成员str申请了动态储存空间,并设置了输入的字符串//并没有改变实参A中... 阅读全文
posted @ 2016-05-26 01:28 01Turing 阅读(1664) 评论(1) 推荐(0) 编辑
摘要: // 复制构造函数.cpp : 定义控制台应用程序的入口点。//复制构造函数:类(const 类&对象(随便起))/*Box(const Box&box){length = box.length;width = box.width;height = box.height;}*/ #include "stdafx.h"#includeusing namespace std;class Box{pri... 阅读全文
posted @ 2016-05-25 23:25 01Turing 阅读(169) 评论(0) 推荐(0) 编辑