Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This type of operation is actually the basis for implementing the constant reoccurring template pattern, where inside the base-class you actually <code>static_cast</code> the <code>this</code> pointer of the base-class to the derived-class template type. Since <code>S</code> is an unambiguous base class of <code>T</code>, and you are not accessing any members from the <code>static_cast</code> that are not already members of <code>S</code>, I don't see why you would encounter any issues.</p> <p>Section 5.2.8 on static casting in paragraph 5 states:</p> <blockquote> <p>An lvalue of type “<em>cv1</em> B”, where B is a class type, can be cast to type “reference to <em>cv2</em> D”, where D is a class derived (clause 10) from B, if a valid standard conversion from “pointer to D” to “pointer to B” exists (4.10), <em>cv2</em> is the same cv-qualification as, or greater cv-qualification than, <em>cv1</em>, and B is not a virtual base class of D. The result is an lvalue of type “<em>cv2</em> D.” If the lvalue of type “<em>cv1</em> B” is actually a sub-object of an object of type D, the lvalue refers to the enclosing object of type D. Otherwise, the result of the cast is undefined.</p> </blockquote> <p>You seem to be meeting all the requirements that avoid undefined behavior. That is:</p> <ol> <li>Class <code>T</code> is derived from <code>S</code></li> <li>A pointer conversion from <code>S</code> to <code>T</code> does exist since <code>S</code> is both accessible and an unambiguous base-class of <code>T</code> (requirements from 4.10)</li> <li>You are using the same constant-value-qualification for both types</li> <li><code>S</code> is not a virtual base-class of <code>T</code></li> </ol>
    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.
 

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