Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

9
  • 1
    When I do CRTP, in my Derived I do friend Base<Derived>;.
    – Eljay
    Commented Mar 23 at 21:59
  • Agree with @Elijay. Because this is "implementation", it should not be public. But you should make it possible to access by the Base. So "friend" fits very well here.
    – ivan.ukr
    Commented Mar 23 at 22:40
  • "Does the line static_cast<Derived*>(this)->closeImplementation() get invoked in the Base<Derived> class or Derived?" -- The line is inside Base<T>::close(). Why would it be invoked anywhere else? (Don't let yourself be confused by "more or less look like". You can rearrange code to get a better handle on the semantics of a class, but not to understand the syntax.)
    – JaMiT
    Commented Mar 23 at 22:57
  • "I am not fully sure if this line makes sense just yet until we have the inheritance." -- Your reasoning looks good (but imprecise about what is instantiated) up to this point. See class template instantiation -- instantiating the class does not imply instantiating the member functions. Is that close enough to be a duplicate?
    – JaMiT
    Commented Mar 23 at 23:15
  • @JaMiT That is correct that it is inside Base<T>::close but the surrounding closure is not exactly clear to me. Is it executing in the context of the Base class or the Derived class? What type is this here? Does it depend on it's closure?
    – nick2225
    Commented Mar 24 at 0:10