<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: 9.5 &#8212; Overloading unary operators +, -, and !</title>
	<atom:link href="http://www.learncpp.com/cpp-tutorial/95-overloading-unary-operators/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learncpp.com/cpp-tutorial/95-overloading-unary-operators/</link>
	<description></description>
	<pubDate>Mon, 13 Oct 2008 11:26:28 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: davidv</title>
		<link>http://www.learncpp.com/cpp-tutorial/95-overloading-unary-operators/#comment-27500</link>
		<dc:creator>davidv</dc:creator>
		<pubDate>Tue, 16 Sep 2008 03:25:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/95-overloading-operators-and/#comment-27500</guid>
		<description>&lt;pre&gt;
if (nX)
    // do something
&lt;/pre&gt;

should be

&lt;pre&gt;

if (!nX)
    // do something
&lt;/pre&gt;

[ Fixed!  Thank you.  -Alex ]</description>
		<content:encoded><![CDATA[<pre>
if (nX)
    // do something
</pre>
<p>should be</p>
<pre>

if (!nX)
    // do something
</pre>
<p>[ Fixed!  Thank you.  -Alex ]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Learn C++ - &#187; 9.4 &#8212; Overloading the comparison operators</title>
		<link>http://www.learncpp.com/cpp-tutorial/95-overloading-unary-operators/#comment-14404</link>
		<dc:creator>Learn C++ - &#187; 9.4 &#8212; Overloading the comparison operators</dc:creator>
		<pubDate>Mon, 05 May 2008 02:04:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/95-overloading-operators-and/#comment-14404</guid>
		<description>[...] 2007      Prev/Next Posts   &#171; 9.3 &#8212; Overloading the I/O operators &#124; Home &#124; 9.5 &#8212; Overloading unary operators +, -, and ! &#187;     Thursday, October 4th, 2007 at 5:10 [...]</description>
		<content:encoded><![CDATA[<p>[...] 2007      Prev/Next Posts   &laquo; 9.3 &#8212; Overloading the I/O operators | Home | 9.5 &#8212; Overloading unary operators +, -, and ! &raquo;     Thursday, October 4th, 2007 at 5:10 [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.learncpp.com/cpp-tutorial/95-overloading-unary-operators/#comment-11804</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Tue, 15 Apr 2008 18:21:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/95-overloading-operators-and/#comment-11804</guid>
		<description>I think you could do this via overloading typecasts.  If you provide an overloaded boolean conversion operator for your point, then I think the above example would work.  This is covered in lesson &lt;a href="http://www.learncpp.com/cpp-tutorial/910-overloading-typecasts/" rel="nofollow"&gt;9.10&lt;/a&gt;.

However, personally I wouldn't recommend implementing it this way.  The conversion from point to boolean isn't very intuitive.  I think this is better implemented as a member function that returns a boolean result -- in this way, your code will be more self-documenting.  eg:

&lt;pre&gt;
if (cPoint.IsOrigin())
    // etc
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I think you could do this via overloading typecasts.  If you provide an overloaded boolean conversion operator for your point, then I think the above example would work.  This is covered in lesson <a href="http://www.learncpp.com/cpp-tutorial/910-overloading-typecasts/" rel="nofollow">9.10</a>.</p>
<p>However, personally I wouldn&#8217;t recommend implementing it this way.  The conversion from point to boolean isn&#8217;t very intuitive.  I think this is better implemented as a member function that returns a boolean result &#8212; in this way, your code will be more self-documenting.  eg:</p>
<pre>
if (cPoint.IsOrigin())
    // etc
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shaun</title>
		<link>http://www.learncpp.com/cpp-tutorial/95-overloading-unary-operators/#comment-11705</link>
		<dc:creator>Shaun</dc:creator>
		<pubDate>Mon, 14 Apr 2008 12:45:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/95-overloading-operators-and/#comment-11705</guid>
		<description>Is there an operator I can use to overload the usual if() effect? E.g.,

&lt;pre&gt;
if (cPoint)
    cout &lt;&lt; "cPoint is not at the origin." &lt;&lt; endl;
else
    cout &lt;&lt; "cPoint is at the origin." &lt;&lt; endl;
&lt;/pre&gt;

What would happen in this case? Would C++ call the ! operator and reverse the result? Or is there another way to provide a boolean operator?</description>
		<content:encoded><![CDATA[<p>Is there an operator I can use to overload the usual if() effect? E.g.,</p>
<pre>
if (cPoint)
    cout < < "cPoint is not at the origin." << endl;
else
    cout << "cPoint is at the origin." << endl;
</pre>
<p>What would happen in this case? Would C++ call the ! operator and reverse the result? Or is there another way to provide a boolean operator?</pre>
]]></content:encoded>
	</item>
</channel>
</rss>
