﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-bullGao-随笔分类-C++ programming</title><link>http://www.cppblog.com/bestgz/category/3147.html</link><description /><language>zh-cn</language><lastBuildDate>Tue, 20 May 2008 13:07:27 GMT</lastBuildDate><pubDate>Tue, 20 May 2008 13:07:27 GMT</pubDate><ttl>60</ttl><item><title>HugeInteger 加减乘法实现</title><link>http://www.cppblog.com/bestgz/archive/2006/12/20/16653.html</link><dc:creator>bullGao</dc:creator><author>bullGao</author><pubDate>Wed, 20 Dec 2006 07:03:00 GMT</pubDate><guid>http://www.cppblog.com/bestgz/archive/2006/12/20/16653.html</guid><wfw:comment>http://www.cppblog.com/bestgz/comments/16653.html</wfw:comment><comments>http://www.cppblog.com/bestgz/archive/2006/12/20/16653.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/bestgz/comments/commentRss/16653.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/bestgz/services/trackbacks/16653.html</trackback:ping><description><![CDATA[
		<p>举例：</p>
		<p>HugeInt.h:</p>
		<p> </p>
		<pre>#ifndef HUGEINT_H
#define HUGEINT_H

#include &lt;iostream&gt;

<span style="COLOR: #0000ff">using</span> std::ostream;

<span style="COLOR: #0000ff">class</span> HugeInt {
	<span style="COLOR: #0000ff">friend</span> ostream &amp;<span style="COLOR: #0000ff">operator</span> &lt;&lt; ( ostream &amp;, <span style="COLOR: #0000ff">const</span> HugeInt &amp; );

<span style="COLOR: #0000ff">public</span>:
	HugeInt( <span style="COLOR: #0000ff">long</span> = 0 );
	HugeInt( <span style="COLOR: #0000ff">const</span><span style="COLOR: #0000ff">char</span> * );

	HugeInt <span style="COLOR: #0000ff">operator</span> + ( <span style="COLOR: #0000ff">const</span> HugeInt &amp; );
	HugeInt <span style="COLOR: #0000ff">operator</span> + ( <span style="COLOR: #0000ff">int</span> );
	HugeInt <span style="COLOR: #0000ff">operator</span> + ( <span style="COLOR: #0000ff">const</span><span style="COLOR: #0000ff">char</span> * );

	HugeInt <span style="COLOR: #0000ff">operator</span> * ( <span style="COLOR: #0000ff">int</span> );
	HugeInt <span style="COLOR: #0000ff">operator</span> * ( <span style="COLOR: #0000ff">const</span> HugeInt &amp; );

<span style="COLOR: #0000ff">private</span>:
	<span style="COLOR: #0000ff">short</span> integer[ 30 ];

};

#endif</pre>
		<p> </p>
		<p>HugeInt.cpp:</p>
		<p> </p>
		<pre>#include &lt;cctype&gt;
#include &lt;cstring&gt;

#include "<span style="COLOR: #8b0000">hugeint.h</span>"

HugeInt::HugeInt( <span style="COLOR: #0000ff">long</span><span style="COLOR: #0000ff">value</span> )
{
	<span style="COLOR: #0000ff">for</span> ( <span style="COLOR: #0000ff">int</span> i = 0; i &lt;= 29; i++ )
		integer[ i ] = 0;

	<span style="COLOR: #0000ff">for</span> ( <span style="COLOR: #0000ff">int</span> j = 29; <span style="COLOR: #0000ff">value</span> != 0 &amp;&amp; j &gt;= 0; j-- ){
		integer[ j ] = <span style="COLOR: #0000ff">value</span> % 10;
		<span style="COLOR: #0000ff">value</span> /= 10;

	}

}

HugeInt::HugeInt( <span style="COLOR: #0000ff">const</span><span style="COLOR: #0000ff">char</span> *<span style="COLOR: #0000ff">string</span> )
{
	<span style="COLOR: #0000ff">for</span> ( <span style="COLOR: #0000ff">int</span> i = 0; i &lt;= 29; i++ )
		integer[ i ] = 0;

	<span style="COLOR: #0000ff">int</span> length = strlen( <span style="COLOR: #0000ff">string</span> );

	<span style="COLOR: #0000ff">for</span> ( <span style="COLOR: #0000ff">int</span> j = 30 - length, k = 0; j &lt;= 29; j++, k++ )

		<span style="COLOR: #0000ff">if</span> ( isdigit( <span style="COLOR: #0000ff">string</span>[ k ] ) )
			integer[ j ] = <span style="COLOR: #0000ff">string</span>[ k ] - '0';

}

HugeInt HugeInt::<span style="COLOR: #0000ff">operator</span> + ( <span style="COLOR: #0000ff">const</span> HugeInt &amp;op2 )
{
	HugeInt temp;
	<span style="COLOR: #0000ff">int</span> carry = 0;

	<span style="COLOR: #0000ff">for</span> ( <span style="COLOR: #0000ff">int</span> i = 29; i &gt;= 0; i-- ){
		temp.integer[ i ] = integer[ i ] + op2.integer[ i ] + carry;

		<span style="COLOR: #0000ff">if</span> ( temp.integer[ i ] &gt; 9 ) {
			temp.integer[ i ] %= 10;
			carry = 1;

		}

		<span style="COLOR: #0000ff">else</span>
			carry = 0;

	}

	<span style="COLOR: #0000ff">return</span> temp;

}

HugeInt HugeInt::<span style="COLOR: #0000ff">operator</span> + ( <span style="COLOR: #0000ff">int</span> op2 )
{
	<span style="COLOR: #0000ff">return</span> *<span style="COLOR: #0000ff">this</span> + HugeInt( op2 );

}

HugeInt HugeInt::<span style="COLOR: #0000ff">operator</span> + ( <span style="COLOR: #0000ff">const</span><span style="COLOR: #0000ff">char</span> *op2 )
{
	<span style="COLOR: #0000ff">return</span> *<span style="COLOR: #0000ff">this</span> + HugeInt( op2 );

}

HugeInt HugeInt::<span style="COLOR: #0000ff">operator</span> * ( <span style="COLOR: #0000ff">const</span> HugeInt &amp;mul )
{
	HugeInt temp;
	HugeInt tempT;
	HugeInt tempN;
	<span style="COLOR: #0000ff">int</span> carry = 0;
	<span style="COLOR: #0000ff">int</span> n = 0;

	<span style="COLOR: #0000ff">for</span> ( <span style="COLOR: #0000ff">int</span> i = 29; i &gt;= 0; i-- ){
		
		<span style="COLOR: #0000ff">for</span> ( <span style="COLOR: #0000ff">int</span> t = 0; t &lt;= 29; t++ ){
			tempT.integer[ t ] = 0;
			tempN.integer[ t ] = 0;

		}

		<span style="COLOR: #0000ff">for</span> ( <span style="COLOR: #0000ff">int</span> j = 29; j &gt;= 0; j-- ){
			tempT.integer[ j ] = integer[ j ] * mul.integer[ i ] + carry;

			<span style="COLOR: #0000ff">if</span> ( tempT.integer[ j ] &gt; 9 ){
				carry = tempT.integer[ j ] / 10;
				tempT.integer[ j ] %= 10;				

			}

 			<span style="COLOR: #0000ff">else</span>
				carry = 0;

		}
		
		<span style="COLOR: #0000ff">for</span> ( <span style="COLOR: #0000ff">int</span> y = 29; y &gt;= 0; y-- )
			tempN.integer[ y - n ] = tempT.integer[ y ];

		++n;

		temp = temp + tempN;

	}

	<span style="COLOR: #0000ff">return</span> temp;

}

HugeInt HugeInt::<span style="COLOR: #0000ff">operator</span> * ( <span style="COLOR: #0000ff">int</span> mul )
{
	<span style="COLOR: #0000ff">return</span> *<span style="COLOR: #0000ff">this</span> * HugeInt( mul );

}

ostream &amp;<span style="COLOR: #0000ff">operator</span> &lt;&lt; ( ostream &amp;output, <span style="COLOR: #0000ff">const</span> HugeInt &amp;num )
{
	<span style="COLOR: #0000ff">int</span> i;

	<span style="COLOR: #0000ff">for</span> ( i = 0; ( num.integer[ i ] == 0 ) &amp;&amp; ( i &lt;= 29 ); i++ )
		;

	<span style="COLOR: #0000ff">if</span> ( i == 30 )
		output &lt;&lt; 0;
	<span style="COLOR: #0000ff">else</span><span style="COLOR: #0000ff">for</span> ( ; i &lt;= 29; i++ )
			output &lt;&lt; num.integer[ i ];

	<span style="COLOR: #0000ff">return</span> output;

}</pre>
		<p> </p>
		<p>main.cpp:</p>
		<p> </p>
		<pre>#include &lt;iostream&gt;

<span style="COLOR: #0000ff">using</span> std::cout;
<span style="COLOR: #0000ff">using</span> std::endl;

#include "<span style="COLOR: #8b0000">hugeint1.h</span>"

<span style="COLOR: #0000ff">int</span> main()
{
	HugeInt n1( 7654321 );
	HugeInt n2( 7891234 );
	HugeInt n3( "<span style="COLOR: #8b0000">9999999999999999999999999</span>" );
	HugeInt n4( "<span style="COLOR: #8b0000">1</span>" );
	HugeInt n5;
	HugeInt n6( 1234 );
	HugeInt n7( 3478 );

	cout &lt;&lt; "<span style="COLOR: #8b0000">n1 is </span>" &lt;&lt; n1 &lt;&lt; "<span style="COLOR: #8b0000">\nn2 is </span>" &lt;&lt; n2
		 &lt;&lt; "<span style="COLOR: #8b0000">\nn3 is </span>" &lt;&lt; n3 &lt;&lt; "<span style="COLOR: #8b0000">\nn4 is </span>" &lt;&lt; n4
		 &lt;&lt; "<span style="COLOR: #8b0000">\nn5 is </span>" &lt;&lt; n5 &lt;&lt; "<span style="COLOR: #8b0000">\nn6 is </span>" &lt;&lt; n6
		 &lt;&lt; "<span style="COLOR: #8b0000">\nn7 is </span>" &lt;&lt; n7 &lt;&lt; "<span style="COLOR: #8b0000">\n\n</span>";

	n5 = n1 + n2;
	cout &lt;&lt; n1 &lt;&lt; "<span style="COLOR: #8b0000"> + </span>" &lt;&lt; n2 &lt;&lt; "<span style="COLOR: #8b0000"> = </span>" &lt;&lt; n5 &lt;&lt; "<span style="COLOR: #8b0000">\n\n</span>";

	cout &lt;&lt; n3 &lt;&lt; "<span style="COLOR: #8b0000"> + </span>" &lt;&lt; n4 &lt;&lt; "<span style="COLOR: #8b0000">\n= </span>" &lt;&lt; ( n3 + n4 )
		 &lt;&lt; "<span style="COLOR: #8b0000">\n\n</span>";

	n5 = n1 + 9;
	cout &lt;&lt; n1 &lt;&lt; "<span style="COLOR: #8b0000"> + </span>" &lt;&lt; 9 &lt;&lt; "<span style="COLOR: #8b0000"> = </span>" &lt;&lt; n5 &lt;&lt; "<span style="COLOR: #8b0000">\n\n</span>";

	n5 = n2 + "<span style="COLOR: #8b0000">10000</span>";
	cout &lt;&lt; n2 &lt;&lt; "<span style="COLOR: #8b0000"> + </span>" &lt;&lt; "<span style="COLOR: #8b0000">10000</span>" &lt;&lt; "<span style="COLOR: #8b0000"> = </span>" &lt;&lt; n5 &lt;&lt; endl;

	n5 = n7 * n6;
	cout &lt;&lt; n7 &lt;&lt; "<span style="COLOR: #8b0000"> * </span>" &lt;&lt; n6 &lt;&lt; "<span style="COLOR: #8b0000"> = </span>" &lt;&lt; n5 &lt;&lt; endl;

	<span style="COLOR: #0000ff">return</span> 0;

}</pre>
		<p> </p>
		<p>输出结果为：<br /><img height="203" alt="{1586B489-88E0-4FE4-A107-B2A2CB761E60}0.jpg" src="http://www.cppblog.com/images/cppblog_com/bestgz/%7B1586B489-88E0-4FE4-A107-B2A2CB761E60%7D0.jpg" width="222" border="0" /></p>
<img src ="http://www.cppblog.com/bestgz/aggbug/16653.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/bestgz/" target="_blank">bullGao</a> 2006-12-20 15:03 <a href="http://www.cppblog.com/bestgz/archive/2006/12/20/16653.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>作业 HugeInteger 运算符 * 重载  完成结果记录</title><link>http://www.cppblog.com/bestgz/archive/2006/12/20/16651.html</link><dc:creator>bullGao</dc:creator><author>bullGao</author><pubDate>Wed, 20 Dec 2006 06:53:00 GMT</pubDate><guid>http://www.cppblog.com/bestgz/archive/2006/12/20/16651.html</guid><wfw:comment>http://www.cppblog.com/bestgz/comments/16651.html</wfw:comment><comments>http://www.cppblog.com/bestgz/archive/2006/12/20/16651.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/bestgz/comments/commentRss/16651.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/bestgz/services/trackbacks/16651.html</trackback:ping><description><![CDATA[
		<p>
		</p>
		<p> </p>
		<pre>HugeInt HugeInt::<span style="COLOR: #0000ff">operator</span> * ( <span style="COLOR: #0000ff">const</span> HugeInt &amp;mul )
{
	HugeInt temp;
	HugeInt tempT;
	HugeInt tempN;
	<span style="COLOR: #0000ff">int</span> carry = 0;
	<span style="COLOR: #0000ff">int</span> n = 0;

	<span style="COLOR: #0000ff">for</span> ( <span style="COLOR: #0000ff">int</span> i = 29; i &gt;= 0; i-- ){
		
		<span style="COLOR: #0000ff">for</span> ( <span style="COLOR: #0000ff">int</span> t = 0; t &lt;= 29; t++ ){
			tempT.integer[ t ] = 0;
			tempN.integer[ t ] = 0;

		}

		<span style="COLOR: #0000ff">for</span> ( <span style="COLOR: #0000ff">int</span> j = 29; j &gt;= 0; j-- ){
			tempT.integer[ j ] = integer[ j ] * mul.integer[ i ] + carry;

			<span style="COLOR: #0000ff">if</span> ( tempT.integer[ j ] &gt; 9 ){
				carry = tempT.integer[ j ] / 10;
				tempT.integer[ j ] %= 10;				

			}

 			<span style="COLOR: #0000ff">else</span>
				carry = 0;

		}
		
		<span style="COLOR: #0000ff">for</span> ( <span style="COLOR: #0000ff">int</span> y = 29; y &gt;= 0; y-- )            <font color="#008000">// 移位处理</font>
			tempN.integer[ y - n ] = tempT.integer[ y ];

		++n;

		temp = temp + tempN;

	}

	<span style="COLOR: #0000ff">return</span> temp;

}</pre>
		<p> </p>
		<p>       考虑到乘法运算，比如12 * 34，那么4先和12做乘法，然后3和12做乘法，之后两数相加得出结果，但是需要注意的是：3与12的乘积要左移一位后再与4和12的乘积做加法。依此类推，推之更大的数。</p>
		<p>       主要是这个移位处理，费了我好多时间，终于搞定了~</p>
<img src ="http://www.cppblog.com/bestgz/aggbug/16651.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/bestgz/" target="_blank">bullGao</a> 2006-12-20 14:53 <a href="http://www.cppblog.com/bestgz/archive/2006/12/20/16651.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Keyword typedef</title><link>http://www.cppblog.com/bestgz/archive/2006/12/10/16249.html</link><dc:creator>bullGao</dc:creator><author>bullGao</author><pubDate>Sun, 10 Dec 2006 15:08:00 GMT</pubDate><guid>http://www.cppblog.com/bestgz/archive/2006/12/10/16249.html</guid><wfw:comment>http://www.cppblog.com/bestgz/comments/16249.html</wfw:comment><comments>http://www.cppblog.com/bestgz/archive/2006/12/10/16249.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/bestgz/comments/commentRss/16249.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/bestgz/services/trackbacks/16249.html</trackback:ping><description><![CDATA[
		<p>
		</p>
		<h3>
				<a>
				</a>
				<sup>
				</sup>typedef</h3>
		<p>
				<b>typedef</b>
				<i>type-declaration synonym</i>
				<b>;</b>
		</p>
		<p>The <b>typedef</b> keyword defines a synonym for the specified <i>type-declaration</i>. The identifier in the <i>type-declaration</i> becomes another name for the type, instead of naming an instance of the type. You cannot use the <b>typedef</b> specifier inside a function definition. </p>
		<p>A <b>typedef</b> declaration introduces a name that, within its scope, becomes a synonym for the type given by the <i>decl</i>-<i>specifiers</i> portion of the declaration. In contrast to the <b>class</b>, <b>struct</b>, <b>union</b>, and <b>enum</b> declarations, <b>typedef</b> declarations do not introduce new types — <u>they introduce new names for existing types</u>. </p>
		<p>
				<b>Example</b>
				<br />
				<br />
		</p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000"> Example of the typedef keyword</span>
				<span style="COLOR: #008000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #000000">typedef unsigned </span>
				<span style="COLOR: #0000ff">long</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">ulong</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">ulong</span>
				<span style="COLOR: #000000"> ul;     </span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000"> Equivalent to "unsigned long ul;"</span>
				<span style="COLOR: #008000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />typedef </span>
				<span style="COLOR: #0000ff">struct</span>
				<span style="COLOR: #000000"> mystructtag<br /><img id="Codehighlighter1_143_181_Open_Image" onclick="this.style.display='none'; Codehighlighter1_143_181_Open_Text.style.display='none'; Codehighlighter1_143_181_Closed_Image.style.display='inline'; Codehighlighter1_143_181_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_143_181_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_143_181_Closed_Text.style.display='none'; Codehighlighter1_143_181_Open_Image.style.display='inline'; Codehighlighter1_143_181_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_143_181_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_143_181_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />   </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000">   i;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />   </span>
						<span style="COLOR: #0000ff">float</span>
						<span style="COLOR: #000000"> f;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />   </span>
						<span style="COLOR: #0000ff">char</span>
						<span style="COLOR: #000000">  c;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000"> mystruct;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />mystruct ms;   </span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000"> Equivalent to "struct mystructtag ms;"</span>
				<span style="COLOR: #008000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />typedef </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> (</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">funcptr)();  </span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000"> funcptr is synonym for "pointer<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />                           </span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">    to function returning int"</span>
				<span style="COLOR: #008000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />funcptr table[</span>
				<span style="COLOR: #000000">10</span>
				<span style="COLOR: #000000">];   </span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000"> Equivalent to "int (*table[10])();"<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
		</div>
<img src ="http://www.cppblog.com/bestgz/aggbug/16249.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/bestgz/" target="_blank">bullGao</a> 2006-12-10 23:08 <a href="http://www.cppblog.com/bestgz/archive/2006/12/10/16249.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[转]C++怎么学?</title><link>http://www.cppblog.com/bestgz/archive/2006/12/07/16107.html</link><dc:creator>bullGao</dc:creator><author>bullGao</author><pubDate>Thu, 07 Dec 2006 13:31:00 GMT</pubDate><guid>http://www.cppblog.com/bestgz/archive/2006/12/07/16107.html</guid><wfw:comment>http://www.cppblog.com/bestgz/comments/16107.html</wfw:comment><comments>http://www.cppblog.com/bestgz/archive/2006/12/07/16107.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/bestgz/comments/commentRss/16107.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/bestgz/services/trackbacks/16107.html</trackback:ping><description><![CDATA[首先声明：本人对之也只能说略之一二(C++太博大了:))<br />  孟岩先生曾经提过"C++需要自由的心",我要说"C++需要自由的心和手",我敢肯定我想的自由和孟岩先生的自由是不同的.<br />因为我的自由就个人诠释是 ："用自己的思路来自由的写验证性的usecase"<br />  就个人的学习心得而言 ：
<p>1.在你学习C++的过程中,你首先需要扎实的实践一本C++基础教程,这个教程不在深而在全.使你能够全览之.最好结合基本数据结构来练习.不要整天Hello World~~Hello MM的.</p><p>2.再下来你需要《(More)Effective C++》,它使你可以对C++也多了份思考,也了解到一些技巧和误区,不过,你需要同步实践,不然可能一时你并不能真正掌握这些技巧、避开误区.</p><p>3.提高,你需要：(下面的书可能已经讲烂了:))</p><p>  《Design Pattern》 ：个人感觉,设计模式虽说是一种思维方式,具体实现上,只是<br />                        对OOP语言的发掘和巧妙组合而已.而且这里组合是主要的,<br />                        特性是有限的,这本书中有几个模式没用虚特性的? <br />   C++ Standard Document: 在你用它来做专项研究的时候,就会体会到什么才叫真正的<br />                                          全而深 (自然指在语法和语义的阐述上). <br />  《STL源码剖析》 ：没有深厚的功底,想来个闭门造车独挑STL源码是不可能的.<br />                                  不过,这本说也重在关键技术的讲解和引导罢了~~<br />                                   这里关于GP和STL的名著不少，本人没看过。不做品评。<br />  《 Inside The C++ Object Model》：最具价值的一本书,没了它,C++永远是个迷,哪怕<br />                                    你浸淫之N载~~<br />  《Moden In C++ Design》 ：这里的很多思路是你自己的思维很难接触到的~~：)<br />                            我不得不佩服Andrei Alexandrescu.</p><p>  市面上其它的C++书籍可牛车载,我感觉除了《The Design And Evolution Of C++》是异品,值得一读.其它的不建议花太多的时间,哪怕是Bjarne Stroustrup、Stanley B.Lippman等的作品.自然,你有时间读更好,反正我现在有点后悔,当初只顾多,不顾深读,反复读.经典的书不在本数多,在于每本读的遍数多.一经验之谈,BBS上经常有人,在介绍COM技术书籍时,想也不想的指出,入门级&lt;&lt;Inside The COM&gt;&gt;.是这样的吗?我想,正如Dale Rogerson所说,将这本书完全看懂,你就是COM专家了~~书中,作者很多话可能你没有注意到,因为你还不懂之,对之没感觉,一遍翻下来,感觉 哦~~简单~全看了 :) 这些书,跟国内的很多书籍最大的不同就是<br />国内书籍的作者写的出,可能自己还不懂:)Copy什么资料上的:)??</p><p>4.浸淫一门语言本身的语法语义再久,你不一定能够深入它的精妙之处.<br />  你需要学习应用这门语言的实作品(技术),你可以研究一些FrameWork或是一些具体的技术 如CORBA、COM等.就个人而已,有心接触C++十个月左右,对于Virtual的认识有过几次较大的的改变.在《 Inside The C++ Object Model》中算第一次,在《COM本质论》中关于COM对二进制兼容布局需求而用虚机制来解决是第二次,到目前为止,使我对virtual流下最深刻印象的是在Automation技术中组件由于环境是否有能力分析virtual结构而导致是否需要分发接口的问题.如果,整天抱着《C++语法语义深入》这样的书,我不知你何时才能真正了解C++很多的特性.<br />  即使你可以对别人说上一大套,这行啊~那不行啊~~云云~~:) </p><p>在这整个的过程中,我喜欢这样对学弟说,你需要经常将C++的各种特性在脑中反复混合酝踉,这也是我强调学基础时,要求教材知识点全的原因.经常的,为了研究某些特性而自由的写、修改、增加UseCase,是我自认为很好的一个习惯.整天记他人的经验之言,不知几个月后还记得几层:)?</p><p>   也许上面的叙述是概括了些:)?</p><p>   总之,我认为学习C++,需要多思考(譬如你想想为什么模板类继承不支持virtual、模板<br />                                   类继承,基类实例和继承类实例产生的关系是什么样的)、<br />                      多写usecase、<br />                      多将一堆特性混合酝晾（譬如模板类<br />                                  成员签名、多种嵌套模板类成员签名、嵌套类与包裹类生命期<br />                                 控制等等)<br />                      <br />                      要尽早选择应用方向(这点很重要,附加个人观点：大多数人认为理论很<br />                                         难，可是我要说：应用一样是有难度的:)).</p><p>                      将00工程学中的理论适时的来对照自己的行为.<br />     </p><p>后话：<br />    上面提到,就应用而已,比较语言的是没有什么意义的.然而我想说的是,不敢想象<br />没有经过C++锤炼的人,可以深入的研究C#(事实上，我一直也不人为C#比C++好学，只是他们的深入点是不同的，冒昧说一句，C++中很多难度是人为制造出来的),就目前的情况来说,还有就是由于C++历史、<br />社团、资源等因素.</p><img src ="http://www.cppblog.com/bestgz/aggbug/16107.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/bestgz/" target="_blank">bullGao</a> 2006-12-07 21:31 <a href="http://www.cppblog.com/bestgz/archive/2006/12/07/16107.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>