C++ Logo

std-discussion

Advanced search

Re: Rditorial changes relative to an example in the section 13.8.2 Explicit instantiation

From: Maris Razvan <razvyboy2004_at_[hidden]>
Date: Wed, 31 Jul 2019 14:38:13 +0300
Hello,

[temp.explicit] p. 4 states:

    "A declaration of a function template, a variable template, a
member function or static data member of a class template, or a member
function template of a class or class template shall precede an
explicit instantiation of that entity. [...]"

So a preceding declaration of the function template is necessary.

Also, [temp.explicit] p. 7 states:

    "[...] Otherwise, for an explicit instantiation definition the
definition of a function template, a variable template, a member
function template, or a member function or static data member of a
class template shall be present in every translation unit in which it
is explicitly instantiated."

>From these two paragraphs it follows that a declaration of a member
function of a class template is required to precede the explicit
instantiation (declaration/definition). Furthermore, if it is an
explicit instantiation definition, the definition of a member function
of a class template is required to be present in the translation unit,
however is it not necessary to precede the explicit instantiation
definition.

On Wed, Jul 31, 2019 at 1:34 PM Vladimir Grigoriev via Std-Discussion
<std-discussion_at_[hidden]> wrote:
>
> In the paragraph #4 of the section 13.8.2 Explicit instantiation there is the following example
>
> template<class T> class Array { void mf(); };
> template class Array<char>;
> template void Array<int>::mf();
>
>
> Should it be
>
> template<class T> class Array { void mf(); };
> template class Array<char>;
> extern template void Array<int>::mf();
>
> because there is no definition of the member function mf.
>
> 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_at_[hidden]
> http://lists.isocpp.org/mailman/listinfo.cgi/std-discussion

Received on 2019-07-31 06:40:22