Re: template specializiation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This information from the ISO 14882 spec might help understand:
14.7.3.6
If a template, a member template or the member of a class template isexplicitly specialized then that specializationshall be declared before the first use of that specialization thatwould cause an implicit instantiationto take place, in every translation unit in which such a use occurs;no diagnostic is required. If the programdoes not provide a definition for an explicit specialization andeither the specialization is used in away that would cause an implicit instantiation to take place or themember is a virtual member function, theprogram is ill-formed, no diagnostic required. An implicitinstantiation is never generated for an explicitspecialization that is declared but not defined. [Example:template<class T> class Array { /* ... */ };template<class T> void sort(Array<T>& v) { /* ... */ }void f(Array<String>& v){sort(v); //use primary template// sort(Array<T>&), T is String}template<> void sort<String>(Array<String>& v); // error: specialization// after use of primary templatetemplate<> void sort<>(Array<char*>& v); // OK: sort<char*> not yet used—end example]
corey
On 7/7/05, Eljay Love-Jensen <eljay@xxxxxxxxx> wrote:> Hi Thomas,> > Hmmm, unusual situation (for me).> > Using...> http://www.comeaucomputing.com/tryitout/> > I tend to trust (EDG's front end) Comeau C++'s error message (strict mode, -tused) on this one.> > How to unravel this riddle, I'm not sure.  Sorry.> > --Eljay> > - - - - -> struct A> {>   const A* a;> };> > template <const char* c>> struct B> {>   static const A b;> };> > extern const char c[1]="";> extern const char d[1]="";> > template<>> const A B<c>::b => {>   &B<d>::b> };> template<>> const A B<d>::b = // Line 21> {>   &B<c>::b> };> - - - - -> > Comeau C/C++ 4.3.3 (Aug  6 2003 15:13:37) for ONLINE_EVALUATION_BETA1> Copyright 1988-2003 Comeau Computing.  All rights reserved.> MODE:strict errors C++> > "ComeauTest.c", line 21: error: explicit specialization of member>           "B<c>::b [with c=d]" must precede its first use>   const A B<d>::b =>                 ^> > "ComeauTest.c", line 24: warning: parsing restarts here after previous syntax error>   };>    ^> > 1 error detected in the compilation of "ComeauTest.c".> > >

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux