摘要: // 构造函数与析构函数2.cpp : 定义控制台应用程序的入口点。//学习动态内存单元的申请 #include "stdafx.h"#includeusing namespace std;class Student{public: Student(); Student(int pid, char*pname, float s); void modify(float s); ... 阅读全文
posted @ 2016-05-24 03:32 01Turing 阅读(94) 评论(0) 推荐(0) 编辑
摘要: // 构造函数与析构函数.cpp : 定义控制台应用程序的入口点。//要学习的两点://要想表现出析构函数,必须在对象外面加大括号!!// while (cin.get() != '\n') num++;#include "stdafx.h"#includeusing namespace std;class Count{public: Count(); ~Count(); ... 阅读全文
posted @ 2016-05-24 03:09 01Turing 阅读(151) 评论(0) 推荐(0) 编辑
摘要: //构造函数含有含默认值的参数 #include "stdafx.h"#includeusing namespace std;class Box{public: Box(int w = 10, int h = 10, int len = 10); int volume();private: int height; int width; int length;}; Bo... 阅读全文
posted @ 2016-05-24 02:54 01Turing 阅读(525) 评论(0) 推荐(0) 编辑
摘要: // simple stack.cpp : 定义控制台应用程序的入口点。// #include "stdafx.h"#includeusing namespace std;const int SIZE = 100;class Stack{ public: void init() { position = 0; } ... 阅读全文
posted @ 2016-05-23 04:38 01Turing 阅读(156) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2016-05-22 18:02 01Turing 阅读(87) 评论(0) 推荐(0) 编辑
摘要: // test.cpp : 定义控制台应用程序的入口点。// #include "stdafx.h"#includeusing namespace std;const int i = 100;const int j = i * 3; int main(){ const int *x; x = &i;//x是一个指针,它指向一个const int,即x可以指向任何标识符(即它不是... 阅读全文
posted @ 2016-05-20 16:21 01Turing 阅读(118) 评论(0) 推荐(0) 编辑
摘要: 先来一张Google与nexus,加油啦! 用构造函数确保初始化 下面是一个带构造函数的类的简单例子 class X { int i; public: X(); //constructor } 当一个对象被定义时: void f() { X a; } 此时a就好像是一个int:为这个对象分配内存,但是当程序执行到a的序列点时,构造函数自动调用,传递到构造函数的第一个参数(秘密)是this指针... 阅读全文
posted @ 2016-05-09 01:43 01Turing 阅读(168) 评论(0) 推荐(0) 编辑
摘要: // 构造函数2.cpp : 定义控制台应用程序的入口点。// #include "stdafx.h"#includeusing namespace std;class Box{public: Box(); Box(int, int, int); //声明带参数的构造函数 int volume(); //声明计算体积的函数pri... 阅读全文
posted @ 2016-05-06 14:58 01Turing 阅读(266) 评论(0) 推荐(0) 编辑
摘要: 类是一种复杂的数据类型,它是将不同类型的数据和与这些数据相关的操作封装在一起的集合体。这有点像C语言中的结构,唯一不同的就是结构没有定义所说的“数据相关的操作”,“数据相关的操作”就是我们平常经常看到的“方法”,因此,类具有更高的抽象性,类中的数据具有隐藏性,类还具有封装性。 类的结构(也即类的组成)是用来确定一类对象的行为的,而这些行为是通过类的内部数据结构和相关的操作来确定的。这些行为是通... 阅读全文
posted @ 2016-05-06 14:08 01Turing 阅读(643) 评论(0) 推荐(0) 编辑
摘要: 一、预备知识―程序的内存分配 一个由C/C++编译的程序(更严密的说应该是进程)占用的内存分为以下几个部分 1、栈区(stack)― 由编译器自动分配释放 ,存放函数的参数值,局部变量的值等。其操作方式类似于数据结构中的栈。 2、堆区(heap) ― 一般由程序员分配释放, 若程序员不释放,程序结束 阅读全文
posted @ 2016-05-05 01:10 01Turing 阅读(188) 评论(0) 推荐(0) 编辑