<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	
	>
<channel>
	<title>
	Comments on: How to Emulate The &#8220;super&#8221; Keyword In C++	</title>
	<atom:link href="https://www.fluentcpp.com/2017/12/26/emulate-super-base/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.fluentcpp.com/2017/12/26/emulate-super-base/</link>
	<description>Jonathan Boccara&#039;s blog</description>
	<lastBuildDate>Thu, 22 Nov 2018 22:31:00 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.5.3</generator>
	<item>
		<title>
		By: AndreyT		</title>
		<link>https://www.fluentcpp.com/2017/12/26/emulate-super-base/#comment-1484</link>

		<dc:creator><![CDATA[AndreyT]]></dc:creator>
		<pubDate>Thu, 22 Nov 2018 22:31:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1324#comment-1484</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2017/12/26/emulate-super-base/#comment-751&quot;&gt;Botet Escriba Vicente J.&lt;/a&gt;.

What you are using in this case is called &lt;i&gt;injected class name&lt;/i&gt;. Inside some invented template class &#039;SomeClass&#039; injected name &#039;SomeClass&#039; refers to the current specialization of &lt;code&gt;SomeClass&lt;/code&gt; template. However, this injected name obeys the same rules as any other nested type declaration.

In particular, when you refer to a nested name of a class type that happens to be a _dependent_ type (i.e. a type that depends on some yet-unknown template parameters), you have to use the keyword `typename` to refer to that nested type. 

This is exactly the reason for the problem in your case. The inherited name `Shape` is a nested name of class `NA::NB::NC::Shape&lt;A&gt;`. The latter still depends on a template parameter `A` (the other parameters are &quot;fixed&quot;, but `A` is still unknown). So, the error you are observing is essentially the same as the one in this case

&lt;pre&gt;&lt;code&gt;
tempate  struct S { using type = T; }
template  struct X
{
  using A = S::type; 
  // ERROR: `S` is a dependent type, keyword `typename` is required!

  using B = typename S::type; 
  // OK, this is the correct form

  using C = S::type; 
  // OK, `S` is not a dependent type, so `typename` is not needed
}
&lt;/code&gt;&lt;/pre&gt;

The problem is not that your derived class is template. The problem is that your base class still depends on template parameter `A`, which makes it a dependent type and which enables this `typename` requirement. Unfortunately, there&#039;s no &quot;short&quot; syntax for this.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2017/12/26/emulate-super-base/#comment-751">Botet Escriba Vicente J.</a>.</p>
<p>What you are using in this case is called <i>injected class name</i>. Inside some invented template class &#8216;SomeClass&#8217; injected name &#8216;SomeClass&#8217; refers to the current specialization of <code>SomeClass</code> template. However, this injected name obeys the same rules as any other nested type declaration.</p>
<p>In particular, when you refer to a nested name of a class type that happens to be a _dependent_ type (i.e. a type that depends on some yet-unknown template parameters), you have to use the keyword `typename` to refer to that nested type. </p>
<p>This is exactly the reason for the problem in your case. The inherited name `Shape` is a nested name of class `NA::NB::NC::Shape<a>`. The latter still depends on a template parameter `A` (the other parameters are &#8220;fixed&#8221;, but `A` is still unknown). So, the error you are observing is essentially the same as the one in this case</p>
<pre><code>
tempate  struct S { using type = T; }
template  struct X
{
  using A = S::type; 
  // ERROR: `S` is a dependent type, keyword `typename` is required!

  using B = typename S::type; 
  // OK, this is the correct form

  using C = S::type; 
  // OK, `S` is not a dependent type, so `typename` is not needed
}
</code></pre>
<p>The problem is not that your derived class is template. The problem is that your base class still depends on template parameter `A`, which makes it a dependent type and which enables this `typename` requirement. Unfortunately, there&#8217;s no &#8220;short&#8221; syntax for this.</a></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: AndreyT		</title>
		<link>https://www.fluentcpp.com/2017/12/26/emulate-super-base/#comment-1483</link>

		<dc:creator><![CDATA[AndreyT]]></dc:creator>
		<pubDate>Thu, 22 Nov 2018 22:14:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1324#comment-1483</guid>

					<description><![CDATA[There&#039;s a serious hidden problem present in the last approach to declaring `base_type` (i.e. the one that refers to &quot;Boost Spirit&quot; as a source). In this case you are basically using the _last_ declaration in the class to make type alias `base_type` to refer to the class itself. The idea is that other declarations located above will see the _inherited_ declaration of `base_type` (inherited from superclass). This will work in many contexts. But this already has a distinctive smell of danger: a danger typically associated with self-referential declarations.

In C++ declarations of class member are separated into two distinctive groups. Declarations from one group can only see the portion of the class declared _above_ them. Declarations from the other group can always see the class in its entirety, including what&#039;s declared below. This latter group is what will definitely have serious issues with this approach to declaring `base_type`.

For example, definitions of class member functions will always see the class a fully defined, in its entirety, regardless of where the function definition is placed (in-class or out-of-class). So, in your case any member function body of class `Shape` will see `base_type` as an alias for `Shape` itself. What do you think will happen in member functions definitions like

void Shape::draw() const override
{
base_type::draw();
}

Yes, you guessed it: this function actually calls itself. It is infinitely recursive.

So, please, be very careful with this &quot;Boost Spirit&quot; approach - it has a very limited usability in some very well controlled contexts. It is not viable for general use.]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a serious hidden problem present in the last approach to declaring `base_type` (i.e. the one that refers to &#8220;Boost Spirit&#8221; as a source). In this case you are basically using the _last_ declaration in the class to make type alias `base_type` to refer to the class itself. The idea is that other declarations located above will see the _inherited_ declaration of `base_type` (inherited from superclass). This will work in many contexts. But this already has a distinctive smell of danger: a danger typically associated with self-referential declarations.</p>
<p>In C++ declarations of class member are separated into two distinctive groups. Declarations from one group can only see the portion of the class declared _above_ them. Declarations from the other group can always see the class in its entirety, including what&#8217;s declared below. This latter group is what will definitely have serious issues with this approach to declaring `base_type`.</p>
<p>For example, definitions of class member functions will always see the class a fully defined, in its entirety, regardless of where the function definition is placed (in-class or out-of-class). So, in your case any member function body of class `Shape` will see `base_type` as an alias for `Shape` itself. What do you think will happen in member functions definitions like</p>
<p>void Shape::draw() const override<br />
{<br />
base_type::draw();<br />
}</p>
<p>Yes, you guessed it: this function actually calls itself. It is infinitely recursive.</p>
<p>So, please, be very careful with this &#8220;Boost Spirit&#8221; approach &#8211; it has a very limited usability in some very well controlled contexts. It is not viable for general use.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: TheRealKorbenDallas		</title>
		<link>https://www.fluentcpp.com/2017/12/26/emulate-super-base/#comment-1482</link>

		<dc:creator><![CDATA[TheRealKorbenDallas]]></dc:creator>
		<pubDate>Thu, 22 Nov 2018 19:32:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1324#comment-1482</guid>

					<description><![CDATA[There&#039;s a serious hidden problem present in the last approach to declaring `base_type` (i.e. the one that refers to &quot;Boost Spirit&quot; as a source). In this case you are basically using the _last_ declaration in the class to make type alias `base_type` to refer to the class itself. This already has a distinctive smell of danger: a danger typically associated with self-referential declarations.

In C++ declarations of class member are separated into two distinctive groups. Declarations from one group can only see the portion of the class declared _above_ them. Declarations from the other group can always see the class in its entirety, including what&#039;s declared below. This latter group is what will definitely have serious issues with this approach to declaring `base_type`.

For example, definitions of class member functions will always see the class a fully defined, in its entirety, regardless of where the function definition is placed (in-class or out-of-class). So, in your case any member function body of class `Shape` will see `base_type` as an alias for `Shape` itself. What do you think will happen in member functions definitions like

void Shape::draw() const override
{
  base_type::draw();
}

Yes, you guessed it: this function actually calls itself. It is infinitely recursive. 

So, please, be very careful with this &quot;Boost Spirit&quot; approach - it has a very limited usability in some very well controlled contexts. It is not viable for general use.]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a serious hidden problem present in the last approach to declaring `base_type` (i.e. the one that refers to &#8220;Boost Spirit&#8221; as a source). In this case you are basically using the _last_ declaration in the class to make type alias `base_type` to refer to the class itself. This already has a distinctive smell of danger: a danger typically associated with self-referential declarations.</p>
<p>In C++ declarations of class member are separated into two distinctive groups. Declarations from one group can only see the portion of the class declared _above_ them. Declarations from the other group can always see the class in its entirety, including what&#8217;s declared below. This latter group is what will definitely have serious issues with this approach to declaring `base_type`.</p>
<p>For example, definitions of class member functions will always see the class a fully defined, in its entirety, regardless of where the function definition is placed (in-class or out-of-class). So, in your case any member function body of class `Shape` will see `base_type` as an alias for `Shape` itself. What do you think will happen in member functions definitions like</p>
<p>void Shape::draw() const override<br />
{<br />
  base_type::draw();<br />
}</p>
<p>Yes, you guessed it: this function actually calls itself. It is infinitely recursive. </p>
<p>So, please, be very careful with this &#8220;Boost Spirit&#8221; approach &#8211; it has a very limited usability in some very well controlled contexts. It is not viable for general use.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jonathan Boccara		</title>
		<link>https://www.fluentcpp.com/2017/12/26/emulate-super-base/#comment-753</link>

		<dc:creator><![CDATA[Jonathan Boccara]]></dc:creator>
		<pubDate>Mon, 15 Jan 2018 16:00:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1324#comment-753</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2017/12/26/emulate-super-base/#comment-751&quot;&gt;Botet Escriba Vicente J.&lt;/a&gt;.

Interesting! I&#039;m not sure why TBH. Maybe this has something to do with ignored names in template base classes. But even this, I&#039;d have thought this would only be about the names inside of the base class.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2017/12/26/emulate-super-base/#comment-751">Botet Escriba Vicente J.</a>.</p>
<p>Interesting! I&#8217;m not sure why TBH. Maybe this has something to do with ignored names in template base classes. But even this, I&#8217;d have thought this would only be about the names inside of the base class.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Botet Escriba Vicente J.		</title>
		<link>https://www.fluentcpp.com/2017/12/26/emulate-super-base/#comment-751</link>

		<dc:creator><![CDATA[Botet Escriba Vicente J.]]></dc:creator>
		<pubDate>Sun, 14 Jan 2018 08:35:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1324#comment-751</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2017/12/26/emulate-super-base/#comment-742&quot;&gt;Jonathan Boccara&lt;/a&gt;.

You are right. It works. However it doesn&#039;t work when the derived class is a template


https://wandbox.org/permlink/yFLkuhvu5amayAoq


Wondering why?]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2017/12/26/emulate-super-base/#comment-742">Jonathan Boccara</a>.</p>
<p>You are right. It works. However it doesn&#8217;t work when the derived class is a template</p>
<p><a href="https://wandbox.org/permlink/yFLkuhvu5amayAoq" rel="nofollow ugc">https://wandbox.org/permlink/yFLkuhvu5amayAoq</a></p>
<p>Wondering why?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jonathan Boccara		</title>
		<link>https://www.fluentcpp.com/2017/12/26/emulate-super-base/#comment-742</link>

		<dc:creator><![CDATA[Jonathan Boccara]]></dc:creator>
		<pubDate>Tue, 09 Jan 2018 19:36:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1324#comment-742</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2017/12/26/emulate-super-base/#comment-735&quot;&gt;Botet Escriba Vicente J.&lt;/a&gt;.

Hey Vincente, it seems to work with clang and gcc, as in this example: http://coliru.stacked-crooked.com/a/40996a85a52fa109. Is that the code that you had in mind?]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2017/12/26/emulate-super-base/#comment-735">Botet Escriba Vicente J.</a>.</p>
<p>Hey Vincente, it seems to work with clang and gcc, as in this example: <a href="http://coliru.stacked-crooked.com/a/40996a85a52fa109" rel="nofollow ugc">http://coliru.stacked-crooked.com/a/40996a85a52fa109</a>. Is that the code that you had in mind?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Botet Escriba Vicente J.		</title>
		<link>https://www.fluentcpp.com/2017/12/26/emulate-super-base/#comment-736</link>

		<dc:creator><![CDATA[Botet Escriba Vicente J.]]></dc:creator>
		<pubDate>Mon, 01 Jan 2018 21:30:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1324#comment-736</guid>

					<description><![CDATA[The alias of base_type on the base class works only for classes at level one. You cannot anymore define your base_type on the class at level 2, so the idiom doesn&#039;t scale.


I prefer to define it on the derived class as it is there where the base_type name has a sense, not on the base class. You need to write the base class name twice however.]]></description>
			<content:encoded><![CDATA[<p>The alias of base_type on the base class works only for classes at level one. You cannot anymore define your base_type on the class at level 2, so the idiom doesn&#8217;t scale.</p>
<p>I prefer to define it on the derived class as it is there where the base_type name has a sense, not on the base class. You need to write the base class name twice however.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Botet Escriba Vicente J.		</title>
		<link>https://www.fluentcpp.com/2017/12/26/emulate-super-base/#comment-735</link>

		<dc:creator><![CDATA[Botet Escriba Vicente J.]]></dc:creator>
		<pubDate>Mon, 01 Jan 2018 21:26:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1324#comment-735</guid>

					<description><![CDATA[In the case you inherit from a template specialization, I believe you need to repeat the whole template specialization, but I &#039;m not sure.


  class Oval : public NA::NB::NC::Shape
  {
    using base_type = Shape;




I&#039;m getting this error
 

  error: use of class template &#039;Shape&#039; requires template arguments

Which compiler are you using?

Have you tried with clang or gcc?

Are you sure this should work?]]></description>
			<content:encoded><![CDATA[<p>In the case you inherit from a template specialization, I believe you need to repeat the whole template specialization, but I &#8216;m not sure.</p>
<p>  class Oval : public NA::NB::NC::Shape<br />
  {<br />
    using base_type = Shape;</p>
<p>I&#8217;m getting this error</p>
<p>  error: use of class template &#8216;Shape&#8217; requires template arguments</p>
<p>Which compiler are you using?</p>
<p>Have you tried with clang or gcc?</p>
<p>Are you sure this should work?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Сергей Шамов		</title>
		<link>https://www.fluentcpp.com/2017/12/26/emulate-super-base/#comment-734</link>

		<dc:creator><![CDATA[Сергей Шамов]]></dc:creator>
		<pubDate>Fri, 29 Dec 2017 14:25:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1324#comment-734</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2017/12/26/emulate-super-base/#comment-733&quot;&gt;Jonathan Boccara&lt;/a&gt;.

Yes, it&#039;s more direct and explicit. But indexes are shorter. Anyway both cases could be implemented with variadic templates (using two standard techniques). The only change you should do in derived class is to replace &#039;class C : public A, B&#039; to something like &#039;class C : public inherit&#060;A,  B&#062;&#039;.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2017/12/26/emulate-super-base/#comment-733">Jonathan Boccara</a>.</p>
<p>Yes, it&#8217;s more direct and explicit. But indexes are shorter. Anyway both cases could be implemented with variadic templates (using two standard techniques). The only change you should do in derived class is to replace &#8216;class C : public A, B&#8217; to something like &#8216;class C : public inherit&lt;A,  B&gt;&#8217;.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jonathan Boccara		</title>
		<link>https://www.fluentcpp.com/2017/12/26/emulate-super-base/#comment-733</link>

		<dc:creator><![CDATA[Jonathan Boccara]]></dc:creator>
		<pubDate>Fri, 29 Dec 2017 14:08:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1324#comment-733</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2017/12/26/emulate-super-base/#comment-732&quot;&gt;Сергей Шамов&lt;/a&gt;.

&quot;base&quot; sounds good to me for single inheritance. In the case of multiple inheritance, isn&#039;t it more direct to access the base classes by their names?]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2017/12/26/emulate-super-base/#comment-732">Сергей Шамов</a>.</p>
<p>&#8220;base&#8221; sounds good to me for single inheritance. In the case of multiple inheritance, isn&#8217;t it more direct to access the base classes by their names?</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
