zwol: stylized sketch of a face in profile (Default)
[personal profile] zwol

Is this well-formed (assume nothing else in the translation unit)?

  template <class T> class R {
    int f();
  };
  template class R<int>;

Now, how about this?

  template <class T> class S {
    int f();
  };
  template <> int S<float>::f() { return 10; }
  template class S<int>;

The crux here being that, in both cases, a definition of S is in scope at the point of the explicit instantiation, but a definition of S::f isn’t (only a specialization, in the second case). Section 14.7 of the C++ standard is so confusing that the authors included a joke about it in the text. GCC doesn’t complain at all, but I don't trust it to get templates exactly pedantically correct.

This account has disabled anonymous posting.
(will be screened if not validated)
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

April 2017

S M T W T F S
      1
2345678
9101112131415
16171819 202122
23242526272829
30      

Style Credit

Expand Cut Tags

No cut tags
Page generated Jan. 7th, 2026 10:39 pm
Powered by Dreamwidth Studios