随笔分类 -  C++ primer 第五版

摘要:sql语句提供了创建数据库,创建表,alter能修改表的结构。insert(插入),update(更新记录),delete(删除记录),select(选择记录) 一个数据库需要解析SQL语句 提供事物操作,后面需要操作日志,以便回滚 表的存储 http://www.ruanyifeng.com/bl 阅读全文
posted @ 2017-10-17 18:27 hchacha 阅读(153) 评论(0) 推荐(0)
摘要:自己写的单例模式 阅读全文
posted @ 2017-10-15 22:46 hchacha 阅读(247) 评论(0) 推荐(0)
摘要:1、要在类外初始化,const 成员变量才能在类内初始化 2、初始化在类外,而不在main函数内 阅读全文
posted @ 2017-10-15 22:43 hchacha 阅读(949) 评论(0) 推荐(0)
摘要:strlen的实现用不用加断言(assert)? http://en.cppreference.com/w/cpp/error/assert 自己写strlen实现会加assert判断空指针,Debug模式下可以方便调试(assert(condition)),不满足断言的条件,会调用abort中断程 阅读全文
posted @ 2017-10-15 21:08 hchacha 阅读(573) 评论(0) 推荐(0)
摘要:1 int Max(int a[], int n) 2 { 3 if (n == 1) return a[0]; 4 return a[0]>Max(a + 1, n - 1) ? a[0] : Max(a + 1, n - 1); 5 } 阅读全文
posted @ 2017-10-15 01:21 hchacha 阅读(1302) 评论(0) 推荐(0)
摘要:题目要求是不超过1s 自己写的代码如下:注意sqrt处的= ,25的质因数为5*5,不加=,25会被判断为素数 1 bool isP(int n) 2 { 3 int dig = 0; 4 int sum = 0; 5 int m = n; 6 while (n) 7 { 8 dig = n % 1 阅读全文
posted @ 2017-10-15 01:15 hchacha 阅读(688) 评论(0) 推荐(0)
摘要:https://www.zhihu.com/question/20200615 函数重载选择最佳匹配函数涉及到类型转换,默认参数 注意:没有int f(int,int)版本,编译器认为上面两个函数都是最佳匹配,argument types are :(int ,int); 最佳的匹配是int f(i 阅读全文
posted @ 2017-10-15 01:00 hchacha 阅读(234) 评论(0) 推荐(0)
摘要:1 int xfun(int *a,int n) 2 { 3 int x = *a;//a的类型是int *,a+1跳动一个int的长度 4 for (int *pa = a + 1; pa < a + n; pa++)//指向同一个类型的指针比较大小,相减是两者之间的元素个数 5 { 6 //st 阅读全文
posted @ 2017-10-15 00:36 hchacha 阅读(4739) 评论(0) 推荐(0)
摘要:c/c++的内存布局:堆,栈,自由存储区(与堆的区别),全局/静态存储区,常量存储区(字符串常量,const常量) http://www.cnblogs.com/QG-whz/p/5060894.html (free store 与heap区别) c程序内存布局 http://blog.csdn.n 阅读全文
posted @ 2017-10-13 00:19 hchacha 阅读(200) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 #include 4 #include 5 6 int main() 7 { 8 std::array s = { 5, 7, 4, 2, 8, 6, 1, 9, 0, 3 }; 9 10 // sort using the default operator()); 19 for (auto a... 阅读全文
posted @ 2017-08-25 10:33 hchacha 阅读(19430) 评论(0) 推荐(0)
摘要:Bjarne Stroustrup 的 C++ 风格与技术 FAQ(中文版) C++常考面试题 (1) (2) 1、尽可能说出static关键字的作用? (1) static修饰函数局部变量(包括main函数里的),该变量不会随着函数作用域的退出而销毁,而是只分配一次内存,下次调用时为上次调用的值。 阅读全文
posted @ 2017-08-21 22:25 hchacha 阅读(302) 评论(0) 推荐(0)
摘要:哪里可以看到c库函数的源码? gnu的c运行库glibc,但是源码的实现却是复杂的,需要考虑效率,stlen源码分析。 c-style字符串有个约定,以空字符结尾,即 '\0' 。 ch存了2个字符,ch1与ch2一样,存了3个字符,即结尾含有 '\0' 。 c不会存字符p,\0标识了结尾。 下面代 阅读全文
posted @ 2017-08-09 01:04 hchacha 阅读(458) 评论(0) 推荐(0)
摘要:SGI源码download,《stl源码剖析》里展示了vector的部分源码: stl里的string menber types 里含有的value_type等也是类型别名,迭代器也是。如果是用户自定义一个string, T,T*的写法明显比value_type、pointer更方便。 阅读全文
posted @ 2017-08-07 19:13 hchacha 阅读(589) 评论(0) 推荐(0)
摘要:1、如何理解迭代器?迭代器不是指针,也似乎不是string这种类型 参考:迭代器与指针的区别是? C++map迭代器的++操作是如何实现的?讨论。iterator提供了遍历STL容器里元素的方式,not-only-read,还可以修改这些元素,如赋值,这需要解引用操作返回的是元素的左值引用。 考虑p 阅读全文
posted @ 2017-08-07 18:31 hchacha 阅读(860) 评论(0) 推荐(0)
摘要:研究与实现相关的layout没多大意义 参考:有关c++中类的虚拟继承sizeof问题 情况1:《剑指offer》纪念版题,sizoef(空类)的结果? 对空类运用sizoef operator,表达式结果是多少?不是0,空类中没有信息,但实例仍需要在内存中有一些信息,这样才能使用,类的内存布局由编 阅读全文
posted @ 2017-08-04 19:40 hchacha 阅读(272) 评论(0) 推荐(0)
摘要:1 #pragma warning(disable:4996) 2 #include<iostream> 3 #include<string> 4 #include<vector> 5 #include<algorithm> 6 #include<cstdio> 7 #include<complex 阅读全文
posted @ 2017-08-04 17:56 hchacha 阅读(608) 评论(0) 推荐(0)
摘要:用char*管理String类的内存,new动态分配,在析构函数中delete char*指向的new出来的内存,一个string类需要实现那些接口可参考标准库里的string: http://www.cplusplus.com/reference/string/string/ 实现思路是:在创建S 阅读全文
posted @ 2017-07-29 02:17 hchacha 阅读(1208) 评论(0) 推荐(0)
摘要:参考:http://chenqx.github.io/2014/09/25/Cpp-Memory-Management/ 内存管理详解 野指针: 一、申请了指针没有初始化,全局指针未初始化编译时无错误,运行会出错,局部指针编译时会报错——unintialized; 二、malloc申请的内存用fre 阅读全文
posted @ 2017-07-21 21:11 hchacha 阅读(166) 评论(0) 推荐(0)
摘要:一些问题: 假设自定义了一个Complex类 Q:为什么需要自定义默认构造函数? A:相比需要显示提供参数的constructor,前者不需要用户提供初始值,如Complex s,如果要用vector容纳Complex对象,要求Complex有自定义的默认构造函数,如下用法才能work: Vecto 阅读全文
posted @ 2017-07-21 14:16 hchacha 阅读(1428) 评论(0) 推荐(0)
摘要:获取内存——创建对象——销毁对象——释放内存 中间出错C++本身是否提供了处理机制,还是需要用户显示处理? 参考: 如何实现一个malloc:http://blog.jobbole.com/75656/ 细说new与malloc的十个不同:http://www.linuxidc.com/Linux/ 阅读全文
posted @ 2017-07-08 13:47 hchacha 阅读(214) 评论(0) 推荐(0)