<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://programmingexamples.net/w/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://programmingexamples.net/w/index.php?action=history&amp;feed=atom&amp;title=CPP%2FClasses%2FConversion_Function</id>
		<title>CPP/Classes/Conversion Function - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://programmingexamples.net/w/index.php?action=history&amp;feed=atom&amp;title=CPP%2FClasses%2FConversion_Function"/>
		<link rel="alternate" type="text/html" href="http://programmingexamples.net/w/index.php?title=CPP/Classes/Conversion_Function&amp;action=history"/>
		<updated>2026-06-13T10:15:11Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.23.5</generator>

	<entry>
		<id>http://programmingexamples.net/w/index.php?title=CPP/Classes/Conversion_Function&amp;diff=319&amp;oldid=prev</id>
		<title>FirstPerson: Created page with '&lt;source lang = &quot;cpp&quot;&gt; #include &lt;iostream&gt; #include &lt;climits&gt; #include &lt;sstream&gt; #include &lt;string&gt;  using namespace std;  template&lt;typename R, typename T&gt; R to(const T&amp; in){ 	stri…'</title>
		<link rel="alternate" type="text/html" href="http://programmingexamples.net/w/index.php?title=CPP/Classes/Conversion_Function&amp;diff=319&amp;oldid=prev"/>
				<updated>2010-07-21T17:29:32Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;#039;&amp;lt;source lang = &amp;quot;cpp&amp;quot;&amp;gt; #include &amp;lt;iostream&amp;gt; #include &amp;lt;climits&amp;gt; #include &amp;lt;sstream&amp;gt; #include &amp;lt;string&amp;gt;  using namespace std;  template&amp;lt;typename R, typename T&amp;gt; R to(const T&amp;amp; in){ 	stri…&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;source lang = &amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;climits&amp;gt;&lt;br /&gt;
#include &amp;lt;sstream&amp;gt;&lt;br /&gt;
#include &amp;lt;string&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using namespace std;&lt;br /&gt;
&lt;br /&gt;
template&amp;lt;typename R, typename T&amp;gt;&lt;br /&gt;
R to(const T&amp;amp; in){&lt;br /&gt;
	stringstream ss;&lt;br /&gt;
	ss &amp;lt;&amp;lt; in;&lt;br /&gt;
	R r = R();&lt;br /&gt;
	ss &amp;gt;&amp;gt; r;&lt;br /&gt;
	return r;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Int{&lt;br /&gt;
private:&lt;br /&gt;
	int var;&lt;br /&gt;
public:&lt;br /&gt;
	Int(int i = 0): var(i){};&lt;br /&gt;
	&lt;br /&gt;
	int value(){ return var; }&lt;br /&gt;
	void value(int i){ var = i; }&lt;br /&gt;
&lt;br /&gt;
	//conversion operator&lt;br /&gt;
	operator string(){ return to&amp;lt;string&amp;gt;(var); }&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
int main(){	&lt;br /&gt;
	Int num = 10;&lt;br /&gt;
	string strNum = num; //use the conversion operator&lt;br /&gt;
	cout &amp;lt;&amp;lt; num.value()  &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; strNum + &amp;quot;.456&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>FirstPerson</name></author>	</entry>

	</feed>