I think that it is a good idea when for most examples in the Standard the reader can copy and paste an example as is and get a compiled program. Otherwise an example that is not compiled and the compiler issues errors will only confuse readers of the Standard.

I am sure that the example I pointed out should be updated.

With best regards,
Vlad from Moscow


You can meet me at http://cpp.forum24.ru/ or www.stackoverflow.com or http://ru.stackoverflow.com

Суббота, 24 августа 2019, 12:46 +03:00 от Will Hawkins via Std-Discussion <std-discussion@lists.isocpp.org>:

On Fri, Aug 23, 2019 at 11:55 PM Tom Honermann via Std-Discussion
<std-discussion@lists.isocpp.org> wrote:
>
> On 8/21/19 11:41 AM, Vladimir Grigoriev via Std-Discussion wrote:
>
> In the p.#2 of the section "13.6.2 Member templates" there is the following example
>
> template <class T>struct A {
> void f(int);
> template <class T2> void f(T2);
> };
>
> template <> void A<int>::f(int) { } // non-template member function
> template <> template <> void A<int>::f<>(int) { } // member function template specialization
>
> int main() {
> A<char> ac;
> ac.f(1); // non-template
> ac.f(’c’); // template
> ac.f<>(1); // template
> }
>
> However there is no definition for example for the specialization of the non-template function for A<char>. So the code is invalid. That is the compiler will issue an error.
>
> A definition is not required for compilation to succeed. A definition is required (somewhere) for the final program to link successfully.
>
>
> Should the template specializations be done in this example for A<char> instead of A<int>?
>
> No. The point of the example is to demonstrate the syntax needed to declare and call specific specializations of those two class template members. The fact that definitions of the two members cannot be (implicitly) instantiated for the A<char> specialization within that translation unit is immaterial.
I apologize that my reply was inaccurate. I completely missed the fact
that there is no actual definition for the template member function f.

Will

>
> Tom.
>
>
> With best regards,
> Vlad from Moscow
>
> You can meet me at http://cpp.forum24.ru/ or www.stackoverflow.com or http://ru.stackoverflow.com
>
>
> --
> Std-Discussion mailing list
> Std-Discussion@lists.isocpp.org
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
--
Std-Discussion mailing list
Std-Discussion@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion