<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Donchel&#039;s Blog</title>
	<atom:link href="http://donchel.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://donchel.wordpress.com</link>
	<description>Just another WordPress.com site</description>
	<lastBuildDate>Tue, 04 Jan 2011 19:58:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='donchel.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Donchel&#039;s Blog</title>
		<link>http://donchel.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://donchel.wordpress.com/osd.xml" title="Donchel&#039;s Blog" />
	<atom:link rel='hub' href='http://donchel.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Multiple-Inheritance with virtual</title>
		<link>http://donchel.wordpress.com/2010/12/14/multiple-inheritance-with-virtual/</link>
		<comments>http://donchel.wordpress.com/2010/12/14/multiple-inheritance-with-virtual/#comments</comments>
		<pubDate>Tue, 14 Dec 2010 17:11:16 +0000</pubDate>
		<dc:creator>Donchel</dc:creator>
				<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://donchel.wordpress.com/?p=172</guid>
		<description><![CDATA[See below pictures, each steps have different memory block. and below is example source for this.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=donchel.wordpress.com&amp;blog=15722071&amp;post=172&amp;subd=donchel&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>See below pictures, each steps have different memory block.</p>
<p><a href="http://donchel.files.wordpress.com/2010/12/inheri-single.jpg"><img class="alignnone size-full wp-image-173" title="inheri-single" src="http://donchel.files.wordpress.com/2010/12/inheri-single.jpg?w=500&#038;h=324" alt="" width="500" height="324" /></a></p>
<p><a href="http://donchel.files.wordpress.com/2010/12/inheri-single-virtual.jpg"><img class="alignnone size-full wp-image-174" title="inheri-single-virtual" src="http://donchel.files.wordpress.com/2010/12/inheri-single-virtual.jpg?w=500&#038;h=323" alt="" width="500" height="323" /></a></p>
<p><a href="http://donchel.files.wordpress.com/2010/12/inheri-double.jpg"><img class="alignnone size-full wp-image-175" title="inheri-double" src="http://donchel.files.wordpress.com/2010/12/inheri-double.jpg?w=500&#038;h=435" alt="" width="500" height="435" /></a></p>
<p><a href="http://donchel.files.wordpress.com/2010/12/inheri-double-virtual.jpg"><img class="alignnone size-full wp-image-176" title="inheri-double-virtual" src="http://donchel.files.wordpress.com/2010/12/inheri-double-virtual.jpg?w=500&#038;h=436" alt="" width="500" height="436" /></a></p>
<p>and below is example source for this.</p>
<pre><pre class="brush: cpp;">
#include &lt;iostream&gt;
using namespace std;

#define _VIRTUAL_
#define _DOUBLE_
//-------------------------------------------
class A{
private:
 int data;
public: 
 A(int data= -123){
 this-&gt;data = data;
 }
 int print(){
 cout&lt;&lt;&quot;A: &quot;&lt;&lt;data&lt;&lt;endl;
 return data;
 }
 ~A(){cout&lt;&lt;&quot;~A:&quot;&lt;&lt;data&lt;&lt;endl;}
};
//-------------------------------------------
#ifdef _VIRTUAL_
class B:virtual public A{
#else
class B:public A{
#endif
private:
 int data;
public: 
 B(int data = -2):A(data*4){
 this-&gt;data = data;
 }
 int print(){
 A::print();
 cout&lt;&lt;&quot;B: &quot;&lt;&lt;data&lt;&lt;endl;
 return data;
 }
 ~B(){ cout&lt;&lt;&quot;~B:&quot;&lt;&lt;data&lt;&lt;endl;  }
};
//-------------------------------------------
#ifdef _DOUBLE_
#ifdef _VIRTUAL_
class C:virtual public A{
#else
class C:public A{
#endif
private:
 int data;
public: 
 C(int data = -3):A(data*3){
 this-&gt;data = data;
 }
 int print(){
 A::print();
 cout&lt;&lt;&quot;c: &quot;&lt;&lt;data&lt;&lt;endl;
 return data;
 }
 ~C(){ cout&lt;&lt;&quot;~C:&quot;&lt;&lt;data&lt;&lt;endl;  }
};
#endif
//-------------------------------------------
#ifdef _DOUBLE_
class D:public B, public C{
#else
class D:public B{
#endif
private:
 int data;
public: 
#ifdef _DOUBLE_
 D(int data):B(10),C(20){
#else
 D(int data):B(10){
#endif
 this-&gt;data = data;
 }
 int print(){
 B::print();
#ifdef _DOUBLE_
 C::print();
#endif
 cout&lt;&lt;&quot;D: &quot;&lt;&lt;data&lt;&lt;endl;
 return data;
 }
 ~D(){ cout&lt;&lt;&quot;~D:&quot;&lt;&lt;data&lt;&lt;endl;  }
};
//-------------------------------------------
int main(){
 //B bb(10);
 D x(10);
 x.print();
 A(B(x)).print();
 return 0;
}

&lt;pre&gt;
&lt;pre&gt;</pre>
</pre>
</pre>
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/donchel.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/donchel.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/donchel.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/donchel.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/donchel.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/donchel.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/donchel.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/donchel.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/donchel.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/donchel.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/donchel.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/donchel.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/donchel.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/donchel.wordpress.com/172/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=donchel.wordpress.com&amp;blog=15722071&amp;post=172&amp;subd=donchel&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://donchel.wordpress.com/2010/12/14/multiple-inheritance-with-virtual/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ae3505b901ddf858730ae88a6196fac1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">donchel</media:title>
		</media:content>

		<media:content url="http://donchel.files.wordpress.com/2010/12/inheri-single.jpg" medium="image">
			<media:title type="html">inheri-single</media:title>
		</media:content>

		<media:content url="http://donchel.files.wordpress.com/2010/12/inheri-single-virtual.jpg" medium="image">
			<media:title type="html">inheri-single-virtual</media:title>
		</media:content>

		<media:content url="http://donchel.files.wordpress.com/2010/12/inheri-double.jpg" medium="image">
			<media:title type="html">inheri-double</media:title>
		</media:content>

		<media:content url="http://donchel.files.wordpress.com/2010/12/inheri-double-virtual.jpg" medium="image">
			<media:title type="html">inheri-double-virtual</media:title>
		</media:content>
	</item>
		<item>
		<title>Virtual function and Overriding</title>
		<link>http://donchel.wordpress.com/2010/11/20/virtual-function-and-overriding/</link>
		<comments>http://donchel.wordpress.com/2010/11/20/virtual-function-and-overriding/#comments</comments>
		<pubDate>Sat, 20 Nov 2010 05:49:40 +0000</pubDate>
		<dc:creator>Donchel</dc:creator>
				<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://donchel.wordpress.com/?p=168</guid>
		<description><![CDATA[in somewhere, if you want to store all object type store by each type of array pointer type cast Pointer type cast set parent (base) class&#8217;s pointer of array anytime can create child class by new created child class&#8217;s address can be assigned to parent class&#8217;s pointer after use, can use delete to release memory <a href="http://donchel.wordpress.com/2010/11/20/virtual-function-and-overriding/" class="excerpt-more-link">[&#8230;]</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=donchel.wordpress.com&amp;blog=15722071&amp;post=168&amp;subd=donchel&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><pre class="brush: cpp;">
Class Person{
int id;
...
}; 
void Person::Print(){
cout&amp;lt;&amp;lt;id&amp;lt;&amp;lt;endl;
}

Class Student:public Person{
int grade,...
}; 
void Student::Print()
{
cout&amp;lt;&amp;lt;id&amp;lt;&amp;lt;&quot;-&quot;&amp;lt;&amp;lt;grade&amp;lt;&amp;lt;endl;
}

Class PartTimeStudent:public Student{
int worktime,
...
};
void PartTimeStudent::Print(){
cout&amp;lt;&amp;lt;id&amp;lt;&amp;lt;&quot;-&quot;&amp;lt;&amp;lt;grade&amp;lt;&amp;lt;&quot;-&quot;&amp;lt;&amp;lt;worktime&amp;lt;&amp;lt;endl;
}

</pre></p>
<ul>
<li>in somewhere, if you want to store all object type</li>
</ul>
<ol>
<li><del>store by each type of array</del></li>
<li>pointer type cast</li>
</ol>
<ul>
<li>Pointer type cast</li>
</ul>
<ol>
<li>set <strong>parent (base) class&#8217;s pointer of array</strong></li>
<li>anytime can create <strong>child class</strong> by <strong>new</strong></li>
<li>created child class&#8217;s address can be assigned to<strong> parent class&#8217;s pointer</strong></li>
<li>after use, can use <strong>delete </strong>to release memory</li>
</ol>
<ul>
<li>Example for saving Class object to an array</li>
</ul>
<p><pre class="brush: cpp;">

Person* prs[5] = {NULL};

prs[0] = new Student(1001,100,...);

prs[1] = new PartTimeStudent(1003,90,5...);

prs[2] = new PartTimeStudent(1005,80,4....);

prs[3] = new Student(1007,99,....);

prs[4] = new PartTimeStudent(1007,100,3);

for(int i=0; i&lt; 5; i++){

prs[i]-&gt;Print();
}
-------------------------
result will
1001
1003
1005
1007
--------------------------
</pre></p>
<p><a href="http://donchel.files.wordpress.com/2010/11/arraypointer.jpg"><img class="alignleft size-medium wp-image-169" title="arraypointer" src="http://donchel.files.wordpress.com/2010/11/arraypointer.jpg?w=300&#038;h=146" alt="" width="300" height="146" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>What we need is.</p>
<ol>
<li><strong><em>call each object not all parent.</em></strong></li>
<li><strong><em>in run time, it needs to decide</em></strong></li>
<li><strong><em>Dynamic Binding</em></strong></li>
<li><strong><em>Polymorphism</em></strong></li>
</ol>
<p>solution is <strong>Virtual</strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/donchel.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/donchel.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/donchel.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/donchel.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/donchel.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/donchel.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/donchel.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/donchel.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/donchel.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/donchel.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/donchel.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/donchel.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/donchel.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/donchel.wordpress.com/168/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=donchel.wordpress.com&amp;blog=15722071&amp;post=168&amp;subd=donchel&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://donchel.wordpress.com/2010/11/20/virtual-function-and-overriding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ae3505b901ddf858730ae88a6196fac1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">donchel</media:title>
		</media:content>

		<media:content url="http://donchel.files.wordpress.com/2010/11/arraypointer.jpg?w=300" medium="image">
			<media:title type="html">arraypointer</media:title>
		</media:content>
	</item>
		<item>
		<title>Parent Class =(assign),*(pointer),&amp;(reference) with Chield Class</title>
		<link>http://donchel.wordpress.com/2010/11/19/parent-class-assignpointerreference-with-chield-class/</link>
		<comments>http://donchel.wordpress.com/2010/11/19/parent-class-assignpointerreference-with-chield-class/#comments</comments>
		<pubDate>Sat, 20 Nov 2010 04:33:38 +0000</pubDate>
		<dc:creator>Donchel</dc:creator>
				<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://donchel.wordpress.com/?p=166</guid>
		<description><![CDATA[Assign Between Parent and Child class cannot assign parent&#8217;s object to a child object. Type cast between parent object and child pointer child pointer cannot point parent object reference has same rule with pointer<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=donchel.wordpress.com&amp;blog=15722071&amp;post=166&amp;subd=donchel&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<ul>
<li>Assign Between Parent and Child class</li>
</ul>
<p>cannot assign parent&#8217;s object to a child object.</p>
<p><pre class="brush: cpp;">

class Person{

char* name;

int age;

};

class Student: public Person{

int grade;

char* school;

};

Parent pr;

Student st;

st = pr;   &lt;-----Error!!

pr = st; &lt;---OK!!

</pre></p>
<ul>
<li>Type cast between <strong>parent object </strong>and <strong>child pointer</strong></li>
</ul>
<p>child pointer <strong>cannot</strong> point parent object</p>
<p><pre class="brush: cpp;">

Parent  pt;

Student * st = &amp;pt; &lt;-------Error

Student ost;

Parent * pt=&amp;ost; &lt;----Ok

</pre></p>
<ul>
<li>reference has same rule with pointer</li>
</ul>
<p><pre class="brush: cpp;">

Parent opt;

Student&amp; rst = opt; &lt;-----Error!!

Student ost;

Parent&amp; rpt = ost; &lt;----Ok!!

</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/donchel.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/donchel.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/donchel.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/donchel.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/donchel.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/donchel.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/donchel.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/donchel.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/donchel.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/donchel.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/donchel.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/donchel.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/donchel.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/donchel.wordpress.com/166/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=donchel.wordpress.com&amp;blog=15722071&amp;post=166&amp;subd=donchel&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://donchel.wordpress.com/2010/11/19/parent-class-assignpointerreference-with-chield-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ae3505b901ddf858730ae88a6196fac1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">donchel</media:title>
		</media:content>
	</item>
		<item>
		<title>Copy Constructor</title>
		<link>http://donchel.wordpress.com/2010/11/16/copy-constructor/</link>
		<comments>http://donchel.wordpress.com/2010/11/16/copy-constructor/#comments</comments>
		<pubDate>Tue, 16 Nov 2010 19:48:24 +0000</pubDate>
		<dc:creator>Donchel</dc:creator>
				<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://donchel.wordpress.com/?p=160</guid>
		<description><![CDATA[Problem of shallow copy 1.just copy primitive variable only in above program, if there is a value for char* ap, Object b=a; will just copy int a value, not pointer ap value. so, here needs deep copy for the object. 2. there is chance application abort when try to delete the char* ap in destructor,  <a href="http://donchel.wordpress.com/2010/11/16/copy-constructor/" class="excerpt-more-link">[&#8230;]</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=donchel.wordpress.com&amp;blog=15722071&amp;post=160&amp;subd=donchel&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><pre class="brush: cpp;">
class object{
 int a;
 char* ap;
public:
 object(int k, char*);
 ......
 //Object(Object&amp; ab);&lt;---copy constructor
 ~Object();
};

Object::Object(int k, char* ap)
{
 this-&gt;a = k;
 this-&gt;ap = new char[strlen(ap)];
 .....
}
Object::~Object()
{
 delete[] ap;
}

void main(){
 Object a = new Object();

 Object b = a; &lt;----problem
 ....doing whaever....
}&lt;&lt;&lt;when exit this main block&gt;&gt;&gt;
</pre></p>
<p>Problem of shallow copy</p>
<p>1.just copy primitive variable only<br />
in above program, if there is a value for char* ap, Object b=a; will just copy int a value, not pointer ap value. so, here needs deep copy for the object.</p>
<p>2. there is chance application abort<br />
when try to delete the char* ap in destructor,  memory violation will be occurred because instance a,b are point same memory to ap. so, create order of object is<br />
a-&gt;b, but destructor order is b-&gt;a. when delete b is no problem, but trying to delete a, there is no more ap. the memory is already deleted in b(b,a point same memory).</p>
<p>* default constructor<br />
if there is no copy constructor, then compiler add default copy constructor. but, it doesn&#8217;t do deep copy.</p>
<p>* when copy the construtor is called<br />
1.initialize a object by exist object</p>
<p><pre class="brush: cpp;">

object a(10);

object b(a);

</pre></p>
<p>2. call a function with passing object argument call by value<br />
<pre class="brush: cpp;">

void functionA(Object obj1)&lt;---call by value
void functionA(Object &amp;obj1)&lt;---this is call by reference

</pre></p>
<p>3. a function returns a object call by value<br />
<pre class="brush: cpp;">

Object functionA(void)&lt;---yes
Object&amp; functionA(void)&lt;---not

</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/donchel.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/donchel.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/donchel.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/donchel.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/donchel.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/donchel.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/donchel.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/donchel.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/donchel.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/donchel.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/donchel.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/donchel.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/donchel.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/donchel.wordpress.com/160/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=donchel.wordpress.com&amp;blog=15722071&amp;post=160&amp;subd=donchel&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://donchel.wordpress.com/2010/11/16/copy-constructor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ae3505b901ddf858730ae88a6196fac1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">donchel</media:title>
		</media:content>
	</item>
		<item>
		<title>friend</title>
		<link>http://donchel.wordpress.com/2010/11/15/friend/</link>
		<comments>http://donchel.wordpress.com/2010/11/15/friend/#comments</comments>
		<pubDate>Mon, 15 Nov 2010 05:57:34 +0000</pubDate>
		<dc:creator>Donchel</dc:creator>
				<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://donchel.wordpress.com/?p=155</guid>
		<description><![CDATA[a class allows a function or a class to access it&#8217;s private area.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=donchel.wordpress.com&amp;blog=15722071&amp;post=155&amp;subd=donchel&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>a class allows a function or a class to access it&#8217;s private area.</p>
<p><pre class="brush: cpp;">
class A{

int a;

public:

friend class B;

friend void Get();

};

void Get(); &lt;----Global Function

class B{

public:

void SetData(A&amp; aa, int val){ aa.a=val;}

};
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/donchel.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/donchel.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/donchel.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/donchel.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/donchel.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/donchel.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/donchel.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/donchel.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/donchel.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/donchel.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/donchel.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/donchel.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/donchel.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/donchel.wordpress.com/155/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=donchel.wordpress.com&amp;blog=15722071&amp;post=155&amp;subd=donchel&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://donchel.wordpress.com/2010/11/15/friend/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ae3505b901ddf858730ae88a6196fac1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">donchel</media:title>
		</media:content>
	</item>
		<item>
		<title>Overload</title>
		<link>http://donchel.wordpress.com/2010/11/15/overload/</link>
		<comments>http://donchel.wordpress.com/2010/11/15/overload/#comments</comments>
		<pubDate>Mon, 15 Nov 2010 05:48:58 +0000</pubDate>
		<dc:creator>Donchel</dc:creator>
				<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://donchel.wordpress.com/?p=150</guid>
		<description><![CDATA[Overload can overload by different arguments Argument count Argument type cannot overload by return type<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=donchel.wordpress.com&amp;blog=15722071&amp;post=150&amp;subd=donchel&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Overload</p>
<p>can overload by different arguments</p>
<p>Argument count</p>
<p><pre class="brush: cpp;">
void function(int a, int b);
void function(int a, int b, int c);
</pre></p>
<p>Argument type</p>
<p><pre class="brush: cpp;">
void func(int a);
void func(double a);
</pre></p>
<ul>
<li><strong>cannot overload by return type</strong></li>
</ul>
<p><pre class="brush: cpp;">
void func(int a);
int func(int a); (X)
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/donchel.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/donchel.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/donchel.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/donchel.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/donchel.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/donchel.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/donchel.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/donchel.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/donchel.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/donchel.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/donchel.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/donchel.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/donchel.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/donchel.wordpress.com/150/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=donchel.wordpress.com&amp;blog=15722071&amp;post=150&amp;subd=donchel&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://donchel.wordpress.com/2010/11/15/overload/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ae3505b901ddf858730ae88a6196fac1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">donchel</media:title>
		</media:content>
	</item>
		<item>
		<title>Linked List</title>
		<link>http://donchel.wordpress.com/2010/11/14/linked-list/</link>
		<comments>http://donchel.wordpress.com/2010/11/14/linked-list/#comments</comments>
		<pubDate>Sun, 14 Nov 2010 23:03:02 +0000</pubDate>
		<dc:creator>Donchel</dc:creator>
				<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://donchel.wordpress.com/?p=145</guid>
		<description><![CDATA[When I store  a data in array, there are some constraints. For example, I cannot adjust the array size dynamically. In addition, It&#8217;s not easy use it to unpredictable data handling program. therefore, linked list is alternative way. here are the example of single linked list and double linked list. Single Linked List .h file <a href="http://donchel.wordpress.com/2010/11/14/linked-list/" class="excerpt-more-link">[&#8230;]</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=donchel.wordpress.com&amp;blog=15722071&amp;post=145&amp;subd=donchel&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When I store  a data in array, there are some constraints. For  example, I cannot adjust the array size dynamically. In addition, It&#8217;s  not easy use it to unpredictable data handling program. therefore,  linked list is alternative way.</p>
<p>here are the example of single linked list and double linked list.</p>
<p>Single Linked List .h file</p>
<p><pre class="brush: cpp;">
class Stack;

class Node{
 int data;
 Node* next;
 Node(int data, Node* next = (Node*)0);
 friend class Stack;
};

class Stack{
 Node* top;
public:
 Stack();
 void push(int data);
 int pop();
 bool isEmpty();
 ~Stack();
};
</pre></p>
<p>this is cpp file</p>
<p><pre class="brush: cpp;">
Node::Node(int data, Node* next){
 this-&gt;data = data;
 this-&gt;next = next;
}

Stack::Stack(){
 this-&gt;top = (Node*)0;
}
void Stack::push(int data){
 Node* newnode = new Node(data,this-&gt;top);
 // newnode-&gt;next = top; already done in constructor
 top = newnode;
}
int Stack::pop(){
 int dataout  = 0;
 if(!isEmpty()){
 dataout= top-&gt;data;
 Node* ToDel = top;
 top = top-&gt;next;
 delete ToDel;
 }
 return dataout;
}
bool Stack::isEmpty(){
 return !top;
}

Stack::~Stack(){
 while(!isEmpty()) pop();
}
</pre></p>
<p>this is double linked list</p>
<p><pre class="brush: cpp;">
class DLL;
class DNode{
 char* _data;
 DNode* _next;
 DNode* _prev;
 DNode(const char* data, DNode* prev = (DNode*)0, DNode* Next= (DNode*)0);
 ~DNode();
 friend class DLL;
};

class DLL{
 DNode* _head;
 DNode* _tail;
 DNode* _cur;
 int _size;
public:
 DLL();
 ~DLL();
 // add to the end
 void Append(const char* data);
 // deletes the cur and if possible
 // cur will point to next otherwise cur
 // will point to prev
 bool Delete();
 // inserts a node between cur and cur-&gt;prev
 // cur becomes the newly inserted node
 void Insert(const char* data);
 bool IsEmpty();
 // copies the content of cur-&gt;data
 // into the data in arg list if possible
 // if failes returns false
 bool Visit(char *data);
 // counts the nodes form the beg to
 // index and returns the data of the node
 // having the fist as zero
 char* operator[](int index);
 // returns number of nodes
 int Size();
};
</pre></p>
<p>cpp file for double linked list</p>
<p><pre class="brush: cpp;">
DNode::DNode(const char* data, DNode* prev, DNode* next){
 _data = new char[strlen(data)+1];
 strcpy(_data, data);
 _next = next;
 _prev = prev;
}
//----------------------------------------------
DNode::~DNode(){
 delete[] _data;
}
//----------------------------------------------
DLL::DLL(){
 _head = _tail = _cur = (DNode*)0;
 _size = 0;
}
//----------------------------------------------
DLL::~DLL(){
 while(Delete());
}
//----------------------------------------------
//Append : add to end of list
void DLL::Append(const char* data){
 DNode* nn = new DNode(data,_tail);
 if(!IsEmpty()){
 _tail-&gt;_next = nn;
 _tail = nn;
 }
 else{
 _head=_cur =_tail= nn;
 }
 _size ++ ;
}
//--------------------------------------------
//delete from head
bool DLL::Delete(){
 bool retn = false;
 if(!IsEmpty()){
 DNode* tm = _cur;
 if(_cur-&gt;_next != _cur &amp;&amp; tm-&gt;_next){
 _cur = tm-&gt;_next;
 _cur-&gt;_prev = tm-&gt;_prev;
 }
 else{
 _cur = tm-&gt;_prev;
 _cur-&gt;_next = _tail = _cur;
 }
 delete tm;
 retn = true;
 }
 return retn;
}
//--------------------------------------------
//Insert : add to beginning of list
void DLL::Insert(const char* data){
 DNode* tp = new DNode(data,(DNode*)0,_cur);
 if(!IsEmpty()){
 _cur-&gt;_prev = tp;
 _cur = tp;
 }else{
 _head=_cur =_tail= tp;
 }
 _size++;
}
//--------------------------------------------
bool DLL::IsEmpty(){
 return !_head;
}
//--------------------------------------------
char* DLL::operator[](int index){
 _cur = _head;
 int count = 0;
 while(_cur != _tail &amp;&amp; count != index){
 count++;
 _cur = _cur-&gt;_next;
 }
 return (char*)_cur-&gt;_data;
}
//--------------------------------------------
bool DLL::Visit(char *data)
{
 bool retn = false;
 if(!IsEmpty()){
 //data = new char[strlen(_cur-&gt;_data)+1];
 strcpy(data,_cur-&gt;_data);
 retn = true;
 }
 return retn;
}
//--------------------------------------------
int DLL::Size(){
 int count = 0;
 _cur = _head;

 while(_cur != _tail){
 count++;
 _cur = _cur-&gt;_next;
 }
 return count;
}
//--------------------------------------------
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/donchel.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/donchel.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/donchel.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/donchel.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/donchel.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/donchel.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/donchel.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/donchel.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/donchel.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/donchel.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/donchel.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/donchel.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/donchel.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/donchel.wordpress.com/145/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=donchel.wordpress.com&amp;blog=15722071&amp;post=145&amp;subd=donchel&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://donchel.wordpress.com/2010/11/14/linked-list/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ae3505b901ddf858730ae88a6196fac1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">donchel</media:title>
		</media:content>
	</item>
		<item>
		<title>using Predefine</title>
		<link>http://donchel.wordpress.com/2010/10/28/using%c2%a0predefine/</link>
		<comments>http://donchel.wordpress.com/2010/10/28/using%c2%a0predefine/#comments</comments>
		<pubDate>Thu, 28 Oct 2010 21:12:38 +0000</pubDate>
		<dc:creator>Donchel</dc:creator>
				<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://donchel.wordpress.com/?p=142</guid>
		<description><![CDATA[I usually use predefine for declare const variable, but there are several example for debugging and concise my source. First, I can use macro to make argument to string. I can get this result it result of #n, #n can covert the argument,here is n,to string. so, the argument is sizeof(a), it will becoem &#8220;sizeof(a), <a href="http://donchel.wordpress.com/2010/10/28/using%c2%a0predefine/" class="excerpt-more-link">[&#8230;]</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=donchel.wordpress.com&amp;blog=15722071&amp;post=142&amp;subd=donchel&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I usually use predefine for declare const variable, but there are several example for debugging and concise my source.</p>
<p>First, I can use macro to make argument to string.</p>
<p><pre class="brush: cpp;">

#define strprint(n) printf(#n &quot;=%d\n&quot;, n)

void main(....){

int a[5] = { 10, 20, 30, 40, 50   };
strprint(sizeof(a)); //

}

</pre></p>
<p>I can get this result</p>
<p><a href="http://donchel.files.wordpress.com/2010/10/result1.jpg"><img class="alignleft size-full wp-image-143" title="result" src="http://donchel.files.wordpress.com/2010/10/result1.jpg?w=500" alt=""   /></a></p>
<p>it result of #n, #n can covert the argument,here is n,to string. so, the argument is sizeof(a), it will becoem &#8220;sizeof(a), and make one string with &#8220;=%d\n&#8221;.</p>
<p>finally, the result will be <strong>printf(&#8220;sizeof(a)=%d\n&#8221;,n);</strong></p>
<p>Next, we can define a predefine function to get size of array.</p>
<p>for example, if you want to print all value for array a(in above source), you should know the size of array to do loop.</p>
<p><pre class="brush: cpp;">
#define sizeofArray(x) (sizeof(x) / sizeof(*(x + 0)) )

void main(...)
{

int a[5] = { 10, 20, 30, 40, 50   };

int i;

for(i=0; i &lt; sizeofArray(p);i++) printf(&quot;%d-&quot;, p+i);

}

</pre></p>
<p>assert()</p>
<p>sizeof array</p>
<div>#ifndef sizeofArray<br />
#define sizeofArray(x) (sizeof(x) / sizeof(*(x + 0)) )<br />
#endif</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/donchel.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/donchel.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/donchel.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/donchel.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/donchel.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/donchel.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/donchel.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/donchel.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/donchel.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/donchel.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/donchel.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/donchel.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/donchel.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/donchel.wordpress.com/142/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=donchel.wordpress.com&amp;blog=15722071&amp;post=142&amp;subd=donchel&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://donchel.wordpress.com/2010/10/28/using%c2%a0predefine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ae3505b901ddf858730ae88a6196fac1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">donchel</media:title>
		</media:content>

		<media:content url="http://donchel.files.wordpress.com/2010/10/result1.jpg" medium="image">
			<media:title type="html">result</media:title>
		</media:content>
	</item>
		<item>
		<title>Multidimensional Arrays and Pointer</title>
		<link>http://donchel.wordpress.com/2010/10/28/multidimensional-arrays-and-pointer/</link>
		<comments>http://donchel.wordpress.com/2010/10/28/multidimensional-arrays-and-pointer/#comments</comments>
		<pubDate>Thu, 28 Oct 2010 16:19:21 +0000</pubDate>
		<dc:creator>Donchel</dc:creator>
				<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://donchel.wordpress.com/?p=133</guid>
		<description><![CDATA[first, when you declare the array, two case both work in below. Next, if you want to access the value 10, how can you access? is same or different? Yes you can get same address value. but &#38;a[0] is correct value to access the value 10. then what does mean a[3][5]? it doesn&#8217;t mean array <a href="http://donchel.wordpress.com/2010/10/28/multidimensional-arrays-and-pointer/" class="excerpt-more-link">[&#8230;]</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=donchel.wordpress.com&amp;blog=15722071&amp;post=133&amp;subd=donchel&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>first, when you declare the array, two case both work in below.</p>
<p><pre class="brush: cpp;">

/////Case1/////

int a[3][5] = {

{ 10, 20, 30, 40, 50 },
{ 100, 200, 300, 400, 500},
{ 1000, 2000, 3000, 4000, 5000}
};

////Case2////

int x[5] = { 10, 20, 30, 40, 50 };
 int y[5] = { 100, 200, 300, 400, 500};
 int z[5] = { 1000, 2000, 3000, 4000, 5000};
 int a[3][5] = {x,y,z};

</pre></p>
<p>Next, if you want to access the value 10, how can you access?</p>
<p><pre class="brush: cpp;">

&amp;a[0] == &amp;a[0][0] ? Same:Different;

</pre></p>
<p>is same or different? Yes you can get same address value. but &amp;a[0] is correct value to access the value 10.</p>
<p>then what does mean a[3][5]?</p>
<p>it doesn&#8217;t mean array a has 15 int type of values although we can imagine all value are in memory in serial.</p>
<p>a&#8212;&gt;| 10| 20| 30| 40| 50|100| 200| 300| 400|500|1000|2000|3000|4000|5000|&#8230;.</p>
<p>but  a[3][5] means array &#8216;a&#8217; has three arrays, a[0],a[1],a[2].</p>
<p>so, each array has int[5], namely, each array has size five int type array.</p>
<p>array &#8216;a&#8217; is three element array and the first is a[0]. It means a == a[0]</p>
<p><pre class="brush: cpp;">

int* p = a;    //1

int (*q)[5]=a;  //2

int** r = a;  //3

</pre></p>
<p>when you compile with above three case, which is makes no compile error or warning?</p>
<p>VC2010 show me below error for case 1</p>
<p><strong>IntelliSense: a value of type &#8220;int (*)[5]&#8221; cannot be used to initialize an entity of type &#8220;int *&#8221; </strong></p>
<p>for case 3</p>
<p><strong>IntelliSense: a value of type &#8220;int (*)[5]&#8221; cannot be used to initialize an entity of type &#8220;int **&#8221; </strong></p>
<p>however case 2, there is no error and no warning. it means case 2 is correct.</p>
<p>if you want use both case 1 and 3, then you should modify like this</p>
<p><pre class="brush: cpp;">

int* p = (int*)a; //case 1

int** r = (int**)a; //case 3

</pre></p>
<p>again, <strong>&amp;a[0] == int(*)[5]</strong> is true, and <strong>a==&amp;a[0]</strong> true, therefore, <strong>int(*q)[5] == a</strong> is true too.</p>
<p>base on above inference, let&#8217;s think about that</p>
<p>how to access the value 200 with above three case :</p>
<p><pre class="brush: cpp;">

//with this predefine

#define strprint(n) printf(#n &quot;=%d\n&quot;, n)

strprint(*(p+6));
 strprint((*q)[6]); // == strprint(q[1][1]);
 strprint(*(r+6));

</pre></p>
<p>you will get this result.</p>
<p><a href="http://donchel.files.wordpress.com/2010/10/result.jpg"><img class="alignleft size-full wp-image-137" title="result" src="http://donchel.files.wordpress.com/2010/10/result.jpg?w=500" alt=""   /></a></p>
<p>which way is you feel easiest. this is important when you use it to function&#8217;s parameter. it will be totally different. let&#8217;s see.</p>
<p>if you want to make a function which print the value 200,</p>
<p>you will create like this.</p>
<p><pre class="brush: cpp;">
//-----------------------------------
//declare case1
void fun_print(int *p);

//declare case2
void fun_print(int (*p)[4]);

//declare case3
void fun_print(**p);
//----------------------------------------------
//implement case1
void fun_print(*p){   printf(&quot;%d&quot;,p[6]); or printf(&quot;%d&quot;,*(p+6));}

//implement case2
void fun_print(int (*p)[4]){   printf(&quot;%d&quot;,p[1][1]);}

//implement case3
void fun_c3(int **p){printf(&quot;%d\n&quot;,*(p+6));}

//----------------------------------------
//when you call

fun_c1((int*)a);   //case 1 needs type cast
fun_c2(a);         //case2  without type cast
fun_c3((int**)a); //case 3 needs type cast

</pre></p>
<p>furthermore, it needs keep in mind that</p>
<p>a[0]&#8212;&gt;&amp;a[0][0] : a[0] points address of first value of first array</p>
<p>a[1]&#8212;&gt;&amp;a[1][0] : a[1] points address of first value of second array</p>
<p>a[2]&#8212;&gt;&amp;[2][0] : a[2] points address of first value of third array</p>
<p><strong>not the each first value</strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/donchel.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/donchel.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/donchel.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/donchel.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/donchel.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/donchel.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/donchel.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/donchel.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/donchel.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/donchel.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/donchel.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/donchel.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/donchel.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/donchel.wordpress.com/133/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=donchel.wordpress.com&amp;blog=15722071&amp;post=133&amp;subd=donchel&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://donchel.wordpress.com/2010/10/28/multidimensional-arrays-and-pointer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ae3505b901ddf858730ae88a6196fac1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">donchel</media:title>
		</media:content>

		<media:content url="http://donchel.files.wordpress.com/2010/10/result.jpg" medium="image">
			<media:title type="html">result</media:title>
		</media:content>
	</item>
		<item>
		<title>Regular Expression</title>
		<link>http://donchel.wordpress.com/2010/10/26/regular-expression/</link>
		<comments>http://donchel.wordpress.com/2010/10/26/regular-expression/#comments</comments>
		<pubDate>Tue, 26 Oct 2010 16:53:51 +0000</pubDate>
		<dc:creator>Donchel</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://donchel.wordpress.com/?p=45</guid>
		<description><![CDATA[&#160; This is the example of Csharp<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=donchel.wordpress.com&amp;blog=15722071&amp;post=45&amp;subd=donchel&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:left;">&nbsp;</p>
<p><pre class="brush: cpp;">
--------------------------------------------------------------------------------
^ caret             the first line or beginning of string
--------------------------------------------------------------------------------
^aaa                in the beginning of string, if there is &quot;aaa&quot; then true,otherwise false

--------------------------------------------------------------------------------
$ dollar            end of line or end of string
--------------------------------------------------------------------------------
aaa$                in the end of line, if the line end with &quot;aaa&quot;, then true, otherwise false

--------------------------------------------------------------------------------
. period            exact one character
--------------------------------------------------------------------------------
^a.c                &quot;abc&quot;,&quot;adc&quot;,&quot;aZc&quot;,.. are true, &quot;aa&quot; is false
a..b$               end of string with these string,&quot;aaab&quot;,&quot;abbb&quot;,azzb&quot;,..., then true

--------------------------------------------------------------------------------
[]                  bracketmeans reange or group, between two character use &quot;-&quot;
--------------------------------------------------------------------------------
[^xxxx]             ^ inside of [], means not
[:string class:]    string class, alpha, blank,cntrl, digit,graph,lower,print,space,upper,xdigit
[:digit:]           same with [0-9]
[:alpha:]           same with [A-Za-z]
[abc]               same with [a-c]. so, &quot;a&quot;,&quot;b&quot;,&quot;c&quot; one of these are true
[Yy]                Y or y is true
[A-Za-z0-9]         all alphabet and numbers
[-A-Z]              with hyphen and all capital
[^a-z]              except lowercase, all string
[^0-9]              except number, all string
[[:digit:]]         same with [0-9]

--------------------------------------------------------------------------------
{} brace            {} means range or repeat for right before the character
--------------------------------------------------------------------------------
a{3}              repeat 'a' only, so only &quot;aaa&quot; is true
a{3,}             'a' repeat more than three, so &quot;aaa&quot;,&quot;aaaa&quot;,&quot;aaaaa&quot;,... are true
a{3,5}            only &quot;aaa&quot;,&quot;aaaa&quot;,&quot;aaaaa&quot; are true
ab{2,3}           only &quot;abb&quot;,&quot;abbb&quot; are true
[0-9]{2}          two digit number
doc[7-9]{2}       &quot;doc77&quot;,&quot;doc87&quot;,&quot;doc97&quot; ...., are true
[^Zz]{5}          without Z and z, five character, &quot;abcde&quot;, &quot;ttttt&quot;..., are true
.{3,4}er          before &quot;er&quot; needs three or four character, Peter,mother, but not brother

--------------------------------------------------------------------------------
* asterisk        means right before character does appear 0 or more, same as {0,}
--------------------------------------------------------------------------------
ab*c              &quot;ac&quot;, &quot;ackdddd&quot;, &quot;abc&quot;, &quot;abbc&quot;, &quot;abbbbbbbc&quot; , etc are true
*                 there is no previous character, some characters or space are true
.*                &quot;.&quot; means one more character, so one more characters or space are not true
ab*               &quot;b&quot; can repeat 0 or mroe, so 'a', &quot;accc&quot;, &quot;abb&quot;, &quot;abbbbbbb&quot; are true
a*                'a' repeat 0 or more, so k, kdd, sdfrrt, a, aaaa, abb, space, ...
doc[7-9]*         doc7,doc777,doc778989,doc,... are true
[A-Z].*           the string are composed with only capital
like.*            previous character is 'a', so like, likely, liker, likelihood...are true

--------------------------------------------------------------------------------
+  plus           previous a character repeats one or more like {1,}
--------------------------------------------------------------------------------
ab+c              abc, abckdddd, abbc, abbbbbbbc ....are true, but not ac
ab+               repeat 'b' one or more, so &quot; ab&quot;, &quot;abccc&quot;, &quot;abb&quot;, &quot;abbbbbbb&quot;...,
like.+            after &quot;like&quot; one character and one or more, &quot;likely&quot;, liker, likelihood..., but not &quot;like&quot;
[A-Z]+            capital string

--------------------------------------------------------------------------------
? question        previous a character repeat 0 or one
--------------------------------------------------------------------------------
ab?c              only &quot;abc&quot;, &quot;abcd&quot; are true

--------------------------------------------------------------------------------
() parenthesis       it used for group in regular expression
--------------------------------------------------------------------------------
| bar             means or
--------------------------------------------------------------------------------
a|b|c             same as [a-c] means one of 'a','b','c'
yes|Yes           same as [yY]es
korea|japan       &quot;korea&quot; or &quot;japan&quot;

--------------------------------------------------------------------------------
\ backslash       use to display special character in the string
--------------------------------------------------------------------------------
</pre></p>
<p>This is the example of Csharp</p>
<p><pre class="brush: csharp;">
class Validation
{
 public static void Main()
 {
 String strToTest;
 Validation objValidate = new Validation();
 Console.Write(&quot;Enter a String to Test for Alphabets:&quot;);
 strToTest = Console.ReadLine();
 if (objValidate.IsAlpha(strToTest))
 {
 Console.WriteLine(&quot;{0} is Valid Alpha String&quot;, strToTest);
 }
 else
 {
 Console.WriteLine(&quot;{0} is not a Valid Alpha String&quot;, strToTest);
 }
 }
 // Function to test for Positive Integers.
 public bool IsNaturalNumber(String strNumber)
 {
 Regex objNotNaturalPattern = new Regex(&quot;[^0-9]&quot;);
 Regex objNaturalPattern = new Regex(&quot;0*[1-9][0-9]*&quot;);
 return !objNotNaturalPattern.IsMatch(strNumber) &amp;&amp;
 objNaturalPattern.IsMatch(strNumber);
 }
 // Function to test for Positive Integers with zero inclusive
 public bool IsWholeNumber(String strNumber)
 {
 Regex objNotWholePattern = new Regex(&quot;[^0-9]&quot;);
 return !objNotWholePattern.IsMatch(strNumber);
 }
 // Function to Test for Integers both Positive &amp; Negative
 public bool IsInteger(String strNumber)
 {
 Regex objNotIntPattern = new Regex(&quot;[^0-9-]&quot;);
 Regex objIntPattern = new Regex(&quot;^-[0-9]+$|^[0-9]+$&quot;);
 return !objNotIntPattern.IsMatch(strNumber) &amp;&amp; objIntPattern.IsMatch(strNumber);
 }
 // Function to Test for Positive Number both Integer &amp; Real
 public bool IsPositiveNumber(String strNumber)
 {
 Regex objNotPositivePattern = new Regex(&quot;[^0-9.]&quot;);
 Regex objPositivePattern = new Regex(&quot;^[.][0-9]+$|[0-9]*[.]*[0-9]+$&quot;);
 Regex objTwoDotPattern = new Regex(&quot;[0-9]*[.][0-9]*[.][0-9]*&quot;);
 return !objNotPositivePattern.IsMatch(strNumber) &amp;&amp;
 objPositivePattern.IsMatch(strNumber) &amp;&amp;
 !objTwoDotPattern.IsMatch(strNumber);
 }
 // Function to test whether the string is valid number or not
 public bool IsNumber(String strNumber)
 {
 Regex objNotNumberPattern = new Regex(&quot;[^0-9.-]&quot;);
 Regex objTwoDotPattern = new Regex(&quot;[0-9]*[.][0-9]*[.][0-9]*&quot;);
 Regex objTwoMinusPattern = new Regex(&quot;[0-9]*[-][0-9]*[-][0-9]*&quot;);
 String strValidRealPattern = &quot;^([-]|[.]|[-.]|[0-9])[0-9]*[.]*[0-9]+$&quot;;
 String strValidIntegerPattern = &quot;^([-]|[0-9])[0-9]*$&quot;;
 Regex objNumberPattern = new Regex(&quot;(&quot; + strValidRealPattern + &quot;)|(&quot; + strValidIntegerPattern + &quot;)&quot;);
 return !objNotNumberPattern.IsMatch(strNumber) &amp;&amp;
 !objTwoDotPattern.IsMatch(strNumber) &amp;&amp;
 !objTwoMinusPattern.IsMatch(strNumber) &amp;&amp;
 objNumberPattern.IsMatch(strNumber);
 }
 // Function To test for Alphabets.
 public bool IsAlpha(String strToCheck)
 {
 Regex objAlphaPattern = new Regex(&quot;[^a-zA-Z]&quot;);
 return !objAlphaPattern.IsMatch(strToCheck);
 }
 // Function to Check for AlphaNumeric.
 public bool IsAlphaNumeric(String strToCheck)
 {
 Regex objAlphaNumericPattern = new Regex(&quot;[^a-zA-Z0-9]&quot;);
 return !objAlphaNumericPattern.IsMatch(strToCheck);
 }
}
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/donchel.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/donchel.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/donchel.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/donchel.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/donchel.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/donchel.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/donchel.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/donchel.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/donchel.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/donchel.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/donchel.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/donchel.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/donchel.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/donchel.wordpress.com/45/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=donchel.wordpress.com&amp;blog=15722071&amp;post=45&amp;subd=donchel&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://donchel.wordpress.com/2010/10/26/regular-expression/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ae3505b901ddf858730ae88a6196fac1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">donchel</media:title>
		</media:content>
	</item>
	</channel>
</rss>
