www.digitalmars.com         C & C++   DMDScript  

c++ - Explicit instantiation and overloading

reply Christof Meerwald <cmeerw web.de> writes:
template<class T>
struct A
{
  template<class U>
  void f(const U*)
  { }

  void f()
  { }
};

template void A<char>::f();
// Error: no match for function 'f()'


Found in Boost's regex library - unfortunately, I don't know of a clean
workaround...


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw jabber.at
mailto cmeerw at web.de

...and what have you contributed to the Net?
Jan 14 2003
parent reply "news.digitalmars.com" <dthomas cogitoinc.com> writes:
Another compiler has generated this error to me and this is my work-around
(maybe this will help you):
template<class T>
struct A
{
   void f();
};

template<class T>
inline void A::f()
{}

template<>
void A<char>::f();


Apparently, the definition of a member function needs to be external to the
template class in order to do an explicit declaration of that member
function.


"Christof Meerwald" <cmeerw web.de> wrote in message
news:b0218d$1qf3$1 digitaldaemon.com...
 template<class T>
 struct A
 {
   template<class U>
   void f(const U*)
   { }

   void f()
   { }
 };

 template void A<char>::f();
 // Error: no match for function 'f()'


 Found in Boost's regex library - unfortunately, I don't know of a clean
 workaround...


 bye, Christof

 --
 http://cmeerw.org                                 JID: cmeerw jabber.at
 mailto cmeerw at web.de

 ...and what have you contributed to the Net?

Jan 29 2003
next sibling parent "David Thomas" <dthomas cogitoinc.com> writes:
I apologize for the name being "news.digitalmars.com".  I didn't realize
Outlook Express defaulted it.

"news.digitalmars.com" <dthomas   cogitoinc.com> wrote in message
news:b18udi$1him$1 digitaldaemon.com...
 Another compiler has generated this error to me and this is my work-around
 (maybe this will help you):
 template<class T>
 struct A
 {
    void f();
 };

 template<class T>
 inline void A::f()
 {}

 template<>
 void A<char>::f();


 Apparently, the definition of a member function needs to be external to

 template class in order to do an explicit declaration of that member
 function.


 "Christof Meerwald" <cmeerw web.de> wrote in message
 news:b0218d$1qf3$1 digitaldaemon.com...
 template<class T>
 struct A
 {
   template<class U>
   void f(const U*)
   { }

   void f()
   { }
 };

 template void A<char>::f();
 // Error: no match for function 'f()'


 Found in Boost's regex library - unfortunately, I don't know of a clean
 workaround...


 bye, Christof

 --
 http://cmeerw.org                                 JID: cmeerw jabber.at
 mailto cmeerw at web.de

 ...and what have you contributed to the Net?


Jan 29 2003
prev sibling parent "David Thomas" <dthomas cogitoinc.com> writes:
Btw, one does not have to provide a definition to a member function if one
wants to force the programmer to provide an explicit instantiation.  That
way the linker will let the programmer know that there is no definition
available.  I've had occasional need of this.

"news.digitalmars.com" <dthomas   cogitoinc.com> wrote in message
news:b18udi$1him$1 digitaldaemon.com...
 Another compiler has generated this error to me and this is my work-around
 (maybe this will help you):
 template<class T>
 struct A
 {
    void f();
 };

 template<class T>
 inline void A::f()
 {}

 template<>
 void A<char>::f();


 Apparently, the definition of a member function needs to be external to

 template class in order to do an explicit declaration of that member
 function.


 "Christof Meerwald" <cmeerw web.de> wrote in message
 news:b0218d$1qf3$1 digitaldaemon.com...
 template<class T>
 struct A
 {
   template<class U>
   void f(const U*)
   { }

   void f()
   { }
 };

 template void A<char>::f();
 // Error: no match for function 'f()'


 Found in Boost's regex library - unfortunately, I don't know of a clean
 workaround...


 bye, Christof

 --
 http://cmeerw.org                                 JID: cmeerw jabber.at
 mailto cmeerw at web.de

 ...and what have you contributed to the Net?


Jan 29 2003