上一页 1 ··· 51 52 53 54 55 56 57 58 59 ··· 69 下一页
摘要: 1. 类成员为const类型2. 类成员为引用类型#include using namespace std;class A{ public: A(int &v) : i(v), p(v), j(v) {} void print_val() { cout using namespace std;class Base{ public: Base(int a) : val(a) {} private: int val;};class A{ public: A(int v) : p(v), b(v) {} ... 阅读全文
posted @ 2013-12-17 09:07 jihite 阅读(15476) 评论(1) 推荐(6)
摘要: 上代码#include using namespace std;class A{ public: A(int v): j(v + 2), i(j) {} void print_val() { cout using namespace std;class A{ public: A(int v): i(v), j(v + 2) {} void print_val() { cout << "hello:" << i << " " << j << endl;} private: int i; int . 阅读全文
posted @ 2013-12-16 22:56 jihite 阅读(715) 评论(0) 推荐(0)
摘要: 假设文件内容为1. hello1 hello2 hello3 hello42. dsfjdosi3. skfskj ksdfls输出每个单词代码#include #include #include #include #include using namespace std;int main(){ string word; ifstream infile("text"); if(!infile) { cout > word) cout >传到word(间隔福为Tab, Space, Enter)输出每一行代码#include #include... 阅读全文
posted @ 2013-12-09 21:31 jihite 阅读(3754) 评论(0) 推荐(1)
摘要: 本质 '\0'就是8位的00000000,因为字符类型中并没有对应的这个字符,所以这么写。'\0'就是 字符串结束标志。 '\0'是转义字符,意思是告诉编译器,这不是字符0,而是空字符。空字符\0对应的二进制为00000000,而数字0为00110000 原来,在C语言中没有专门的字符串变量,通常用 阅读全文
posted @ 2013-12-09 08:39 jihite 阅读(24124) 评论(2) 推荐(2)
摘要: 源自c++primer 4th, 248页代码#include #include #include using namespace std;int main(){ int ival; while(cin >> ival, !cin.eof()) { cout ::max(), '\n'); continue; } } }几个地方1. 逗号表达式首先计算每一个操作数,然后返回最右边的操作数最为整个操作的结果,因此while(cin >> ival, !cin.eof())看重的只是!cin.eof(),而对前边的cin>>... 阅读全文
posted @ 2013-12-08 17:42 jihite 阅读(3503) 评论(2) 推荐(3)
摘要: 缘起#include #include #include using namespace std; int main(){ ofstream fs; //输出文件流 (正确) ostringstream os; //输出string流(正确) ostream o; //输出普通流 (错误)}解惑头文件iostream定义了三个类iostream, istream, ostream(三个普通流), 都存在这样的问题:不可以直接定义无参数的对象。原因可以从编译器提示看出 类中无参数的构造函数定义为protected,因此不可直接... 阅读全文
posted @ 2013-12-06 23:14 jihite 阅读(1108) 评论(0) 推荐(0)
摘要: 第4章96页,数组维数为变量第8章246. IO对象不可复制、赋值原因是类设计时复制构造函数、赋值函数是私有的,为什么这么设计呢?251. tie举例第15章484 派生类可以恢复,但不可扩大#include #include using namespace std;class base{ public: base(int p1=1, int p2=2, int p3=3) : pub(p1), pri(p2), pro(p3) {} int pub; private: int pri; protected: int p... 阅读全文
posted @ 2013-12-06 22:13 jihite 阅读(296) 评论(0) 推荐(0)
摘要: c++primer 页数:376-379 备份, 很有嚼头#include #include #include using namespace std;class Screen{ public: typedef string::size_type index; Screen(index r, index c) : row(r), col(c), contents(r * c, 0) {}; Screen& set(index r, index c, char val); Screen& set(char val); S... 阅读全文
posted @ 2013-12-02 22:41 jihite 阅读(868) 评论(0) 推荐(0)
摘要: C++内存分配方式详解——堆、栈、自由存储区、全局/静态存储区和常量存储区c++内存分配c/c++中static关键字详解c++ staticc++primer 220------------------------------------------------------------------------------------------------------------------------------------------------------------------在C++中,内存分成5个区栈区(stack) 由编译器自动分配释放 ,存放函数的参数值,局部变量的值等。其操 阅读全文
posted @ 2013-11-30 10:56 jihite 阅读(605) 评论(0) 推荐(0)
摘要: 抽象处理大而复杂的问题的重要手段是抽象,强调事物本质的东西。 对程序抽象而言,一个语言结构的抽象强调的是该结构外部可观察的行为,与该结构的内部实现无关。抽象包括过程抽象和数据抽象。封装封装是把一个语言结构的具体实现细节作为一个黑匣子对该结构的使用者隐藏起来的一种机制,从而符合信息隐藏原则。封装包括过程封装和数据封装。区别 封装考虑内部实现,抽象考虑的是外部行为封装是屏蔽细节,抽象是提取共性图例 阅读全文
posted @ 2013-11-27 23:12 jihite 阅读(2970) 评论(0) 推荐(2)
上一页 1 ··· 51 52 53 54 55 56 57 58 59 ··· 69 下一页