<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.8" -->
<?xml-stylesheet href="https://baszerr.eu/lib/exe/css.php?s=feed" type="text/css"?>
<rss version="2.0">
    <channel xmlns:g="http://base.google.com/ns/1.0">
        <title>BaSzErr - blog:2014:12:15</title>
        <description></description>
        <link>https://baszerr.eu/</link>
        <lastBuildDate>Sun, 05 Apr 2026 22:05:09 +0000</lastBuildDate>
        <generator>FeedCreator 1.8</generator>
        <image>
            <url>https://baszerr.eu/lib/exe/fetch.php?media=wiki:dokuwiki.svg</url>
            <title>BaSzErr</title>
            <link>https://baszerr.eu/</link>
        </image>
        <item>
            <title>rvalue_to_this</title>
            <link>https://baszerr.eu/doku.php?id=blog:2014:12:15:rvalue_to_this</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;rvalue_to_this&quot;&gt;2014-12-15 - rvalue to this&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
rvalue reference to &lt;em&gt;this&lt;/em&gt; allows you to create member functions, callable if &lt;em&gt;this&lt;/em&gt; is in fact rvalue. it is similar to &lt;em&gt;const&lt;/em&gt; member functions. for member function &lt;em&gt;foo()&lt;/em&gt; a syntax would like this:
&lt;/p&gt;
&lt;pre class=&quot;code c&quot;&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; foo&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;&amp;amp;&amp;amp;;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
nice and straight forward. but that&amp;#039;s where &lt;em&gt;const&lt;/em&gt;-analogy breaks. for &lt;em&gt;const&lt;/em&gt; and non-&lt;em&gt;const&lt;/em&gt; overloads one does:
&lt;/p&gt;
&lt;pre class=&quot;code c&quot;&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; foo&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; foo&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
now let&amp;#039;s try it with rvalue:
&lt;/p&gt;
&lt;pre class=&quot;code c&quot;&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; foo&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; foo&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;&amp;amp;&amp;amp;;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
and now computer says “no”:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;error: ‘void X::foo() &amp;amp;&amp;amp;’ cannot be overloaded
 void foo() &amp;amp;&amp;amp;;
      ^
error: with ‘void X::foo()’
 void foo();
      ^&lt;/pre&gt;

&lt;p&gt;
what is going on? at first i though this feature is not yet implemented on GCC. after double checking – it IS implemented… so let&amp;#039;s try clang:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;error: cannot overload a member function with ref-qualifier &amp;#039;&amp;amp;&amp;amp;&amp;#039; with a member function without a ref-qualifier
  void foo() &amp;amp;&amp;amp;;
       ^                    
note: previous declaration is here
  void foo();                    
       ^&lt;/pre&gt;

&lt;p&gt;
as usually clang is a bit more human friendly here. already see the problem? code should look like this:
&lt;/p&gt;
&lt;pre class=&quot;code c&quot;&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; foo&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;&amp;amp;;&lt;/span&gt;  &lt;span class=&quot;co1&quot;&gt;// &amp;lt;-- &#039;&amp;amp;&#039; here...&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; foo&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;&amp;amp;&amp;amp;;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
it appears that member functions, when overload for ref, need proper ref-qualifier on both overloads! why it is so? it is still a mystery to me…
&lt;/p&gt;

&lt;p&gt;
btw: if you wonder about this:
&lt;/p&gt;
&lt;pre class=&quot;code c&quot;&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; foo&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; foo&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;&amp;amp;;&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; foo&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;&amp;amp;&amp;amp;;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
no – it does not work:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;error: cannot overload a member function with ref-qualifier &amp;#039;&amp;amp;&amp;#039; with a member function without a ref-qualifier&lt;/pre&gt;

&lt;/div&gt;
</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Tue, 15 Jun 2021 20:08:56 +0000</pubDate>
        </item>
    </channel>
</rss>
