
C++
文章平均质量分 60
mingpingzhang
这个作者很懒,什么都没留下…
展开
-
Google C++ 编程规范(1.1)
第一章 头文件 第一节 #define保护 所有头文件都应有#define保护以防止多次包含。包含符号的格式应为: 项目>_路径>_文件>_H_。 为了保证符号的唯一性,符号应基于文件在项目文件树中位置,比如文件/src/bar/baz.h就应有如下头文件保护: #ifndef FOO_BAR_BAZ_H_ #define FOO_BAR_BAZ_H_ ... #原创 2012-11-05 08:53:25 · 568 阅读 · 0 评论 -
斐波那契数列
int fun(int num) { if (num == 1 || num == 2) return 1; return fun(num -1 ) + fun(num - 2); } int main() { for(int i = 0; i < 5; ++i) { std::cout << fun(i) << std::endl;原创 2017-06-15 10:50:58 · 253 阅读 · 0 评论 -
将一个结构体变量中的数据传递给另一个函数
将一个结构体变量中的数据传递给另一个函数,有下列3种方法: 用结构体变量名作参数。一般较少用这种方法。用指向结构体变量的指针作实参,将结构体变量的地址传给形参。用结构体变量的引用变量作函数参数。 下面通过一个简单的例子来说明,并对它们进行比较。 【例7.5】有一个结构体变量stu,内含学生学号、姓名和3门课的成绩。要求在main函数中为各成员赋值,在另一函数print中将它们的值原创 2014-08-31 01:53:44 · 5557 阅读 · 0 评论 -
C++ 声明新类型 typedef
在C++中,除了可以声明结构体、共用体、枚举等类型外,还可以用typedef声明一个新的类型名来代替已有的类型如: typedef int INTEGER; //指定用标识符INTEGER代表int类型 typedef float REAL; //指定用REAL代表float类型 这样,以下两行等价: int i,j; float a,b; INTEG原创 2014-08-31 01:46:22 · 1780 阅读 · 0 评论 -
C++ 动态分配内存的(new)之撤销内存的(delete)
在软件开发过程中,常常需要动态地分配和撤销内存空间,例如对动态链表中结点的插入与删除。在C语言中是利用库函数malloc和free来分配和撤销内存空间的。C++提供了较简便而功能较强的运算符new和delete来取代malloc和free函数。 注意: new和delete是运算符,不是函数,因此执行效率高。 虽然为了与C语言兼容,C++仍保留malloc和free函数,但建议用户不用原创 2014-08-31 01:50:59 · 780 阅读 · 0 评论 -
How to Make cURL works with cmake
How to Make cURL works with cmake Recently, I want to learn cURL, so downloaded it and compiled it, and use cmake to manage the project, I wrote a CMakelists.txt as below: cmake_minimum_req原创 2014-08-24 10:27:17 · 1155 阅读 · 0 评论 -
The Leak of The Memory in C++ 1.2
This articles will show how to avoid the leak of the memory in c++, I just use this articles to summerise something, and show how awesome my English is. If someone need Chinese version, just told me.原创 2014-04-27 22:02:15 · 545 阅读 · 0 评论 -
the leak of the memory in c++ 03
The Leak of the Memory in C++ In this chaper I will introduce a new smart pointer which is scoped_ptr; It likes auto_ptr but better. When peopel use auto_ptr, sometimes they forget that auto_原创 2014-05-24 21:52:36 · 494 阅读 · 0 评论 -
Google C++ 编程规范 1.3
Inline Functions 内联函数 ▽Define functions inline only when they are small, say, 10 lines or less. 只有函数非常小,10行以内才定义为内联。 Definition: You can declare functions in a way that allows the compiler to e翻译 2012-11-16 08:08:52 · 798 阅读 · 1 评论 -
Google C++编程规范 1.2
头文件依赖 当前向声明可满足使用的情况下不要使用#include 你包含一个头文件意味引入一个依赖,当头文件发生改变时,你的源代码文件必须重新编译。如果你的头文件包含其他头文件,其他的头文件发生任何一点改变,你源代码文件必须重新编译,因此我们应选择最小依赖,特别是头文件包含其他头文件时。 在你需要包含你自己定义的头文件时使用前向声明,你能减少一大堆头文件。翻译 2012-11-05 13:20:42 · 500 阅读 · 0 评论 -
The Leak of The Memory In C++ 1.1
The Leak of The Memory in C++ (chapter 1) So many people asked me something about the leak of the memory. They said that in C++ you must be careful when use pointer. I must say they were righ原创 2014-04-24 09:03:40 · 472 阅读 · 0 评论