<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>格物致知 &#187; C++</title>
	<atom:link href="http://leeing.org/category/programming-language/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://leeing.org</link>
	<description>keep Thinking</description>
	<lastBuildDate>Fri, 04 Nov 2011 16:20:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
		<item>
		<title>APUE 中的 ourhdr.h 头文件</title>
		<link>http://leeing.org/2010/09/17/ourhdr-header-file-in-apue/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://leeing.org/2010/09/17/ourhdr-header-file-in-apue/#comments</comments>
		<pubDate>Fri, 17 Sep 2010 11:26:03 +0000</pubDate>
		<dc:creator>leeing</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://leeing.org/?p=657</guid>
		<description><![CDATA[《UNIX 环境高级编程》中几乎所有的示例代码都包含了 ourhdr.h 文件，这是作者自行写的一个实现，其源代码如下： #ifndef ourhdr_h #define ourhdr_h #include &#60;sys/types.h&#62; #include &#60;stdio.h&#62; #include &#60;stdlib.h&#62; #include &#60;string.h&#62; #include &#60;unistd.h&#62; #define MAXLINE 4096 #define FILE_MODE (S_IRUSR &#124; S_IWUSR &#124; S_IRGRP &#124; S_IROTH) #define DIR_MODE (FILE_MODE &#124; S_IXUSR &#124; S_IXGRP &#124; S_IXOTH) typedef void Sigfunc(int); #if defined(SIG_IGN) &#38;&#38; !defined(SIG_ERR) #define SIG_ERR ((Sigfunc *)-1) #endif #define min(a,b) ((a) &#60; [...]


Related posts:<ol><li><a href='http://leeing.org/2010/01/31/struct-vs-class-in-cpp/' rel='bookmark' title='Permanent Link: C++ 中 struct 和 class 的联系和区别'>C++ 中 struct 和 class 的联系和区别</a></li>
<li><a href='http://leeing.org/2010/03/09/c-plus-plus-primer-array-and-pointer-part-2/' rel='bookmark' title='Permanent Link: C++ Primer 学习笔记：数组和指针 (2)'>C++ Primer 学习笔记：数组和指针 (2)</a></li>
</ol>]]></description>
		<wfw:commentRss>http://leeing.org/2010/09/17/ourhdr-header-file-in-apue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux 环境编程的一些常识</title>
		<link>http://leeing.org/2010/03/09/some-common-sense-of-linux-programming/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://leeing.org/2010/03/09/some-common-sense-of-linux-programming/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 11:54:40 +0000</pubDate>
		<dc:creator>leeing</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://leeing.org/?p=336</guid>
		<description><![CDATA[杂乱地记录一些在 linux 下编程的常识，主要来自&#60;Beginning Linux Programming&#62; 的第一章。 /bin: 二进制文件目录，用于存放启动系统时用到的二进制文件。 /usr/bin: 用户二进制文件目录，用于存放用户使用的标准程序。 /usr/local/bin: 本地二进制文件目录，用于存放特定软件安装的程序。 /opt: 可选的操作系统组件和第三方应用可以安装在这个目录。可以将路径添加到PATH。 /usr/include: 系统的标准库函数。 /usr/include/sys及 /usr/include/linux: 一般放置依赖于特定系统的头文件。 如果没有用 -o 选项告诉编译器将可执行文件放在何处，则会默认将程序放到一个名为a.out的文件里，而a.out的意思是：assembler output，即汇编输出。 库文件的类型： .a :archive 代表传统的静态函数库，类似于windows中的LIB文件，包含在可执行文件中。 静态库的一个缺点是：如果同时运行多个应用程序，且使用来自同一个函数库时，内存中会有多个相同的拷贝，这将浪费大量的内存和磁盘空间。 .so :shared object 代表共享函数库，类似于windows中的dll文件，在程序运行时加载。 程序使用共享库时的链接方式是这样的：它本身不再包含函数代码，而是引用时可访问的共享代码，当编译好的程序被装载到内存中执行时，函数引用被解析并产生对共享库的调用，如果有必要才被加载到内存中。 可以使用ldd命令来查看程序所信赖的共享库。 在 gcc 中，参数 -lm 表示链接名为libm的库，并且，编译器会优先选择共享库。而 -L则表示添加库的搜索路径。-c 表示阻止编译器创建一个完整的程序。 $ gcc -c bill.c fred.c #生成目标文件 $ ar crv libfoo.a bill.o fred.o   #生成静态库文件 [...]


Related posts:<ol><li><a href='http://leeing.org/2010/04/17/chromium-google-chrome-for-linux/' rel='bookmark' title='Permanent Link: Chromium : Google chrome for linux'>Chromium : Google chrome for linux</a></li>
</ol>]]></description>
		<wfw:commentRss>http://leeing.org/2010/03/09/some-common-sense-of-linux-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C++ Primer 学习笔记：数组和指针 (2)</title>
		<link>http://leeing.org/2010/03/09/c-plus-plus-primer-array-and-pointer-part-2/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://leeing.org/2010/03/09/c-plus-plus-primer-array-and-pointer-part-2/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 10:59:56 +0000</pubDate>
		<dc:creator>leeing</dc:creator>
				<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://leeing.org/?p=330</guid>
		<description><![CDATA[C++ Primer 学习笔记四：数组和指针 (2) 1. 指向const 对象的指针。 如果指针指向const对象，则不允许用指针来改变其所指的const值，C++ 语言强制要求指向const对象的指针也必须具有const特性。 const double *cptr; // cptr may point to a double that is const. 注意这里cptr本身并不是一个const，可以让它指向另一个double对象（可以不是const类型的），但是不能通过cptr来改变所指对象的值。 不能使用void* 指针保存const对象的地址，必须使用const void* 类型的指针保存const对象的地址： const int universe = 42; const void *cpv = &#38;universe; 允许把非const对象的地址赋给指向const对象的指针，例如： double dval = 3.14; const double *cptr = &#38;dval; // const double* 型的指针可以指向double类型对象。 *cptr = 1.0 // [...]


Related posts:<ol><li><a href='http://leeing.org/2010/03/07/c-plus-plus-primer-array-and-pointer-part-1/' rel='bookmark' title='Permanent Link: C++ Primer 学习笔记：数组和指针 (1)'>C++ Primer 学习笔记：数组和指针 (1)</a></li>
<li><a href='http://leeing.org/2010/03/04/c-plus-plus-primer-variable-and-types/' rel='bookmark' title='Permanent Link: C++ Primer 学习笔记：变量和类型'>C++ Primer 学习笔记：变量和类型</a></li>
<li><a href='http://leeing.org/2010/09/17/ourhdr-header-file-in-apue/' rel='bookmark' title='Permanent Link: APUE 中的 ourhdr.h 头文件'>APUE 中的 ourhdr.h 头文件</a></li>
<li><a href='http://leeing.org/2010/03/06/c-plus-plus-primer-stand-library-types/' rel='bookmark' title='Permanent Link: C++ Primer 学习笔记：标准库类型'>C++ Primer 学习笔记：标准库类型</a></li>
</ol>]]></description>
		<wfw:commentRss>http://leeing.org/2010/03/09/c-plus-plus-primer-array-and-pointer-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C++ Primer 学习笔记：数组和指针 (1)</title>
		<link>http://leeing.org/2010/03/07/c-plus-plus-primer-array-and-pointer-part-1/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://leeing.org/2010/03/07/c-plus-plus-primer-array-and-pointer-part-1/#comments</comments>
		<pubDate>Sun, 07 Mar 2010 12:42:17 +0000</pubDate>
		<dc:creator>leeing</dc:creator>
				<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://leeing.org/?p=325</guid>
		<description><![CDATA[C++ Primer 学习笔记三：数组和指针 (1) 1. 现代C++ 中应当尽量使用vector和迭代器类型，避免使用低级的数组和指针。设计良好的程序只有在性能测试时使用vector无法达到性能要求时，才在类实现的内部使用数组和指针。出于遗留系统的原因，还是必须掌握数组的使用方法。 数组的长度是固定的，一经创建就不能添加新的元素。指针则可以像迭代器一样用于遍历和检查数组中的元素。 2. 数组的维数必须用大于等于1的常量表达式定义，此常量表达式只能包含整型字面值常量，枚举常量或者用常量表达式初始化的整型const对象。非const对象和必须到运行时才确定值的const变量不能用于定义数组的维数。 3. 如果没有显式地提供元素初值，则数组元素会像普通变量一样初始化： 在函数体外定义的内置数组，其元素均初始化为0。 在函数体内定义的内置数组，其元素无初始化。 无论数组在哪里定义，如果其元素为类类型，则自动调用该类的默认构造函数进行初始化；如果该类没有默认构造函数，则必须为该数组的元素提供显式的初始化。 4. 不允许数组直接复制或赋值，数组的下标索引应当为size_t类型。 5. 与迭代器不同的是：指针用于指向单个对象，而迭代器只能用于访问容器内的元素。 6. 避免使用未初始化的指针。如果可能的话，除非所指向的对象已经存在，否则不要先定义指针，这样可以避免一个未初始化的指针；如果必须分开赋值，则应当先将指针赋为空值。 7. void* 可以保存任何类型对象的指针，它只支持以下几种操作： 与另一个指针进行比较 向函数传递void* 指针或从函数返回void* 指针 给另一个void* 指针赋值 不允许使用void* 指针操纵它所指向的对象。 8. 指针和引用的比较： 引用总是指向某个对象 ，定义引用时没有初始化是错误的。 赋值行为的差异：给引用赋值修改的是该引用所关联的对象的值，而并不是使引用与另一个对象关联。引用一经初始化就始终指向同一个特定对象（这也是为什么引用必须在定义时初始化的原因）。 例如下面的程序： int ival = 1024, ival2 = 2048; int *pi = &#38;ival, *pi2 = &#38;ival2; pi = pi2 [...]


Related posts:<ol><li><a href='http://leeing.org/2010/03/09/c-plus-plus-primer-array-and-pointer-part-2/' rel='bookmark' title='Permanent Link: C++ Primer 学习笔记：数组和指针 (2)'>C++ Primer 学习笔记：数组和指针 (2)</a></li>
<li><a href='http://leeing.org/2010/03/04/c-plus-plus-primer-variable-and-types/' rel='bookmark' title='Permanent Link: C++ Primer 学习笔记：变量和类型'>C++ Primer 学习笔记：变量和类型</a></li>
<li><a href='http://leeing.org/2010/03/06/c-plus-plus-primer-stand-library-types/' rel='bookmark' title='Permanent Link: C++ Primer 学习笔记：标准库类型'>C++ Primer 学习笔记：标准库类型</a></li>
</ol>]]></description>
		<wfw:commentRss>http://leeing.org/2010/03/07/c-plus-plus-primer-array-and-pointer-part-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>C++ Primer 学习笔记：标准库类型</title>
		<link>http://leeing.org/2010/03/06/c-plus-plus-primer-stand-library-types/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://leeing.org/2010/03/06/c-plus-plus-primer-stand-library-types/#comments</comments>
		<pubDate>Sat, 06 Mar 2010 07:02:56 +0000</pubDate>
		<dc:creator>leeing</dc:creator>
				<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://leeing.org/?p=311</guid>
		<description><![CDATA[C++ Primer 学习笔记二：标准库类型 1. 有一种情况下，必须总是使用完全限定的标准库名字：在头文件中。因为头文件的内容会被预处理器复制到程序中。用#include包含文件时，相当于头文件中的文本将成为我们编写的文件的一部分。如果在头文件中放置using声明，就相当于每个包含此头文件的程序都放置了同一using声明，不论该程序是否需要using声明。而通常，头文件中只应当定义确实必要的东西。 2. 字符串字面值与标准库中的string并不是同一个类型，这是因为历史的原因及C兼容性。 当进行string对象和字符串字面值混合连接操作时，+ 操作符的左右操作数必须至少有一个是string类型的： string str = "hello " + "world" // 非法 string str0 = "world"; string str1 = "hello" + ", " + str0 // 非法 3. 从标准输入读取string，将： 读取并忽略开头所有的空白字符（如空格，换行符，制表符） 读取字符直到再次遇到空白字符，读取终止。 例如，如果输入为：&#8217;        hello world     &#8216;，则实际保存的是: &#8216;hello&#8217; 一种不常见的初始化方式为： string str(n,c)：将str初始化为字符 c 的n个副本。 4. string.empty() 将返回bool值，判断是否为空串。 5. string：size_type。因为string::size()返回的是string::size_type类型的值，string类类型和许多其它库类型都定义了一些配套类型，通过这些配套类型，库类型的使用就可以与机器无关，size_type定义为与unsigned类型（unsigned int或者unsigned long）具有相同的含义，而且可以保证足够大的能够存储任意string对象的长度。为了使用由string类型定义的size_type类型，必须加上string::来限定所使用的size_type是由string类定义的。 任何存储string的size操作结果的变量必须为string::size_type类型。特别重要的是，不要把size的返回值赋给一个int变量，这是为了避免溢出现象的发生。 [...]


Related posts:<ol><li><a href='http://leeing.org/2010/03/09/c-plus-plus-primer-array-and-pointer-part-2/' rel='bookmark' title='Permanent Link: C++ Primer 学习笔记：数组和指针 (2)'>C++ Primer 学习笔记：数组和指针 (2)</a></li>
<li><a href='http://leeing.org/2010/03/04/c-plus-plus-primer-variable-and-types/' rel='bookmark' title='Permanent Link: C++ Primer 学习笔记：变量和类型'>C++ Primer 学习笔记：变量和类型</a></li>
<li><a href='http://leeing.org/2010/03/07/c-plus-plus-primer-array-and-pointer-part-1/' rel='bookmark' title='Permanent Link: C++ Primer 学习笔记：数组和指针 (1)'>C++ Primer 学习笔记：数组和指针 (1)</a></li>
</ol>]]></description>
		<wfw:commentRss>http://leeing.org/2010/03/06/c-plus-plus-primer-stand-library-types/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C++ Primer 学习笔记：变量和类型</title>
		<link>http://leeing.org/2010/03/04/c-plus-plus-primer-variable-and-types/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://leeing.org/2010/03/04/c-plus-plus-primer-variable-and-types/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 12:39:23 +0000</pubDate>
		<dc:creator>leeing</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[编程语言]]></category>

		<guid isPermaLink="false">http://leeing.org/?p=288</guid>
		<description><![CDATA[C++ Primer 学习笔记一 ：变量和基本类型 1. 在C++ 中要理解“初始化不是赋值”，因为初始化是指创建变量并给它赋初始值，而赋值是擦除对象的当前值并用新值代替。虽然只有在编写非常复杂的类时才能凸显这两种方式的区别，但这也是一个关键的概念，而且直接初始化更灵活而且效率更高。 C++中支持两种初始化的形式：复制初始化和直接初始化： int ival(1024) // direct-initialization int ival = 1024 // copy-initialization 2. 在C++语言中，变量必须且仅能定义一次，而且在使用变量之前必须定义或声明变量。为了让多个文件访问相同的变量，C++区分了声明和定义。 a) 变量的定义用于为变量分配存储空间，还可以为变量指定初始值，在一个程序中，变量有且仅有一个定义。 b) 声明用于向程序表明变量的类型和名字。定义也是声明：当定义变量时我们声明了它的类型和名字，可以通过使用extern关键字声明变量名而不定义它： extern int i; // declares but does not define i int i; // declares and defines i 在这里，extern声明不是定义，也不分配存储空间，因为只有定义才分配存储空间。如果声明有初始化，则可以看作是定义： extern double pi = 3.1416 虽然使用了extern，但是这条语句还是定义了pi，分配并初始化了存储空间，只有当extern声明位于函数外部时，才可以含有初始化式。 c) 任何在多个文件中使用的变量都需要有与定义分离的声明，在这种情况下，一个文件含有变量的定义，使用该变量的其它文件则包含此变量的声明（而不是定义）。 d) 通常把一个对象定义在它首次使用的地方，以提高可读性。放置声明的一个约束是，变量只能在其定义处开始到此声明所在的作用域的结束处才可以访问，必须在使用此变量的最外层作用域里面或之前定义变量。 3. 外部变量extern和const，非const变量默认为extern，而要使用const变量能在其它文件中访问，必须显示地指定它为extern。 即必须在最初就定义为：extern const [...]


Related posts:<ol><li><a href='http://leeing.org/2010/03/09/c-plus-plus-primer-array-and-pointer-part-2/' rel='bookmark' title='Permanent Link: C++ Primer 学习笔记：数组和指针 (2)'>C++ Primer 学习笔记：数组和指针 (2)</a></li>
<li><a href='http://leeing.org/2010/03/07/c-plus-plus-primer-array-and-pointer-part-1/' rel='bookmark' title='Permanent Link: C++ Primer 学习笔记：数组和指针 (1)'>C++ Primer 学习笔记：数组和指针 (1)</a></li>
<li><a href='http://leeing.org/2010/03/06/c-plus-plus-primer-stand-library-types/' rel='bookmark' title='Permanent Link: C++ Primer 学习笔记：标准库类型'>C++ Primer 学习笔记：标准库类型</a></li>
</ol>]]></description>
		<wfw:commentRss>http://leeing.org/2010/03/04/c-plus-plus-primer-variable-and-types/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C++ 中 struct 和 class 的联系和区别</title>
		<link>http://leeing.org/2010/01/31/struct-vs-class-in-cpp/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://leeing.org/2010/01/31/struct-vs-class-in-cpp/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 07:13:20 +0000</pubDate>
		<dc:creator>leeing</dc:creator>
				<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://leeing.org/?p=251</guid>
		<description><![CDATA[struct vs class 在 C++ 中class 和 struct  只有两点主要区别： 默认继承权限。默认情况下，class的继承是以private来继承而struct则是按照public进行继承。 成员的默认访问权限。class的成员默认是private权限，struct默认是public权限。 而其它的特性，struct和class基本上，甚至严格来说是一样的: //一个不常见的示例，将 struct 直接改为class也能编译通过。 //编译环境为 GCC 4.4.1 #include &#60;iostream&#62; #include &#60;string&#62; using namespace std; struct bar { private: // 访问权限修饰符 int y; public: bar(){}; //无参构造函数 bar(int a){ y = a;}//带参数的构造函数 ~bar(); //虚构函数 void say(); virtual void func1() = 0; //纯虚函数 }; struct foo: protected [...]


Related posts:<ol><li><a href='http://leeing.org/2010/09/17/ourhdr-header-file-in-apue/' rel='bookmark' title='Permanent Link: APUE 中的 ourhdr.h 头文件'>APUE 中的 ourhdr.h 头文件</a></li>
<li><a href='http://leeing.org/2010/01/17/java-constructor/' rel='bookmark' title='Permanent Link: Java 的构造方法'>Java 的构造方法</a></li>
<li><a href='http://leeing.org/2010/04/30/swing-redirecting-system-out-and-system-err-to-jtextpane-or-jtextarea/' rel='bookmark' title='Permanent Link: Swing : 将 System.out 重定向到 JTextArea 和 JTextPane'>Swing : 将 System.out 重定向到 JTextArea 和 JTextPane</a></li>
</ol>]]></description>
		<wfw:commentRss>http://leeing.org/2010/01/31/struct-vs-class-in-cpp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

