<?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>Open source blog, linux, php, python, security &#187; c++ example</title>
	<atom:link href="http://www.alonon.net/tag/c-example/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.alonon.net</link>
	<description></description>
	<lastBuildDate>Wed, 02 Jun 2010 08:11:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>

   <image>
    <title>Open source blog, linux, php, python, security</title>
    <url>http://1.gravatar.com/avatar/5152c5736f5f8dd9570ffb2f9068e8ab?s=</url>
    <link>http://www.alonon.net</link>
   </image>
		<item>
		<title>C++ Friend Functions</title>
		<link>http://www.alonon.net/c-friend-functions/</link>
		<comments>http://www.alonon.net/c-friend-functions/#comments</comments>
		<pubDate>Mon, 15 Dec 2008 21:02:46 +0000</pubDate>
		<dc:creator>ALonon</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[c++ example]]></category>
		<category><![CDATA[friend functions]]></category>
		<category><![CDATA[friends]]></category>

		<guid isPermaLink="false">http://www.alonon.net/?p=20</guid>
		<description><![CDATA[A class can allow non-member functions and other classes to access its own private data, by making them as friends. This part of C++ tutorial essentially gives two important points. Once a non-member function is declared as a friend, it can access the private data of the class similarly when a class is declared as &#8230; <a href="http://www.alonon.net/c-friend-functions/">Read more <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A class can allow non-member functions and other classes to access its own private data, by making them as  <strong>friends</strong>. This part of C++ tutorial essentially gives two important points.</p>
<ul>
<li>Once a non-member function is declared as a friend, it can access the private data of the class</li>
<li>similarly when a class is declared as a friend, the friend class can have access to the private data of the class which made this a friend</li>
</ul>
<p>Here is an example</p>
<pre lang="cpp">/* Onur AKTAS - alonon.net
 * 15/12/2008
 * Friend Functions
 */
#include <iostream>
using namespace std;
class INTEGER
{
	int num; // private variable
public:
	INTEGER(int n=0) {num = n;} // constructor to assign n to num
	friend void add(INTEGER &#038;x,INTEGER &#038;y); // this is friend function, it is not a member function, and can not write in class
};
void add (INTEGER &#038;x,INTEGER &#038;y) // do not write friend at the begining
{
  cout<<"Addition is: "<<x.num+y.num<<endl; // plus x's num with y's num
}
int main ()
{
	INTEGER x(5);
	INTEGER y(6);
	add(x,y);
	return 0;
}</pre>

	Tags: <a href="http://www.alonon.net/tag/cpp/" title="C++" rel="tag">C++</a>, <a href="http://www.alonon.net/tag/c-example/" title="c++ example" rel="tag">c++ example</a>, <a href="http://www.alonon.net/tag/friend-functions/" title="friend functions" rel="tag">friend functions</a>, <a href="http://www.alonon.net/tag/friends/" title="friends" rel="tag">friends</a><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.alonon.net/my-c-homework/" title="My C++ Homework (May 18, 2009)">My C++ Homework</a> (0)</li>
	<li><a href="http://www.alonon.net/design-patterns/" title="Design Patterns (October 30, 2009)">Design Patterns</a> (0)</li>
	<li><a href="http://www.alonon.net/compile_c_cplus_in_linux/" title="Compile C C++ in linux (November 16, 2008)">Compile C C++ in linux</a> (0)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.alonon.net/c-friend-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
