Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is explicitly disallowed in the standard, even if some versions of VisualStudio do allow it.</p> <p>C++ Standard 7.1.5.3 Elaborated type specifiers, paragraph 2</p> <blockquote> <p>3.4.4 describes how name lookup proceeds for the identifier in an elaborated-type-specifier. If the identifier resolves to a class-name or enum-name, the elaborated-type-specifier introduces it into the declaration the same way a simple-type-specifier introduces its type-name. If the identifier resolves to a typedef-name or a template type-parameter, the elaborated-type-specifier is ill-formed. [Note: this implies that, within a class template with a template type-parameter T, the declaration <em>friend class T</em>; is ill-formed. ]</p> </blockquote> <p>I recognize the code above as a pattern to seal (disallow the extension of) a class. There is another solution, that does not really block the extension but that will flag unadvertidly extending from the class. As seen in <a href="http://stlab.adobe.com/group__adobe__final.html" rel="noreferrer">ADOBE Source Library</a>:</p> <pre><code>namespace adobe { namespace implementation { template &lt;class T&gt; class final { protected: final() {} }; }} #define ADOBE_FINAL( X ) private virtual adobe::implementation::final&lt;T&gt; </code></pre> <p>with the usage:</p> <pre><code>class Sealed : ADOBE_FINAL( Sealed ) {//... }; </code></pre> <p>While it allows extension if you really force it:</p> <pre><code>class SealBreaker : public Sealed, ADOBE_FINAL( Sealed ) { public: SealBreaker() : adobe::implementation::final&lt;Sealed&gt;(), Sealed() {} }; </code></pre> <p>It will restrict users from mistakenly do it.</p> <p><strong>EDIT</strong>: </p> <p>The upcoming C++11 standard does allow you to befriend a type argument with a slightly different syntax:</p> <pre><code>template &lt;typename T&gt; class A { // friend class T; // still incorrect: elaborate type specifier friend T; // correct: simple specifier, note lack of "class" }; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload