Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > getting Error :: explicitly instantiate functional Template

Reply
Thread Tools

getting Error :: explicitly instantiate functional Template

 
 
Pallav singh
Guest
Posts: n/a
 
      09-15-2008
Hi All ,

i writing a shared library ,containing code in template
i trying to explicitly instantiate functional & class
template ........But i am getting Error

#include<iostream>
#include "commonfile.h"

template<typename T>
const T & min(const T & a , const T & b)
{return (a < b ? a : b );}

template<typename T>
const T & max(const T & a , const T & b)
{return (a < b ? b : a );}

template int max(int,int);
template int min(int,int);

> g++ -g commonfile.h commonfile.cc

g++: compilation of header file requested
commonfile.cc:16: template-id `max<int, int>' for `int max(int, int)'
does not
match any template declaration
commonfile.cc:17: template-id `min<int, int>' for `int min(int, int)'
does not
match any template declaration
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      09-15-2008
Pallav singh wrote:
> Hi All ,
>
> i writing a shared library ,containing code in template
> i trying to explicitly instantiate functional & class
> template ........But i am getting Error
>
> #include<iostream>
> #include "commonfile.h"
>
> template<typename T>
> const T & min(const T & a , const T & b)
> {return (a < b ? a : b );}
>
> template<typename T>
> const T & max(const T & a , const T & b)
> {return (a < b ? b : a );}
>
> template int max(int,int);


template<> int max(int,int);

--
Ian Collins.
 
Reply With Quote
 
 
 
 
Pallav singh
Guest
Posts: n/a
 
      09-15-2008
On Sep 15, 1:16*pm, Ian Collins <(E-Mail Removed)> wrote:
> Pallav singh wrote:
> > Hi All ,

>
> > i writing a *shared library ,containing code in template
> > i trying to explicitly instantiate functional & class
> > template *........But i am getting Error

>
> > #include<iostream>
> > #include "commonfile.h"

>
> > template<typename T>
> > const T & min(const T & a , const T & b)
> > {return (a < b ? a : b );}

>
> > template<typename T>
> > const T & max(const T & a , const T & b)
> > {return (a < b ? b : a );}

>
> > template int max(int,int);

>
> template<> int max(int,int);
>
> --
> Ian Collins.

+++++++++++++++++++++++++++++++++++++++++++++
Hi Ian

After using following way of expilicit Instantiation ....compilation
Error goes
But i donot find Symbol w.r.t. function's in my Object File...

Currently i am using gcc version 3.2.3

template<int,int> int max(int,int);
template<int,int> int min(int,int);

>> nm --demangle commonfile.o

U __cxa_atexit
U __dso_handle
00000056 t _GLOBAL__I_commonfile.ccTMZ5vb
U __gxx_personality_v0
0000003e t __tcf_0
00000000 t __static_initialization_and_destruction_0(int, int)
U std::ios_base::Init::Init[in-charge]()
U std::ios_base::Init::~Init [in-charge]()
00000000 b std::__ioinit
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      09-15-2008
Pallav singh wrote:
> On Sep 15, 1:16 pm, Ian Collins <(E-Mail Removed)> wrote:
>> Pallav singh wrote:
>>> Hi All ,
>>> i writing a shared library ,containing code in template
>>> i trying to explicitly instantiate functional & class
>>> template ........But i am getting Error
>>> #include<iostream>
>>> #include "commonfile.h"
>>> template<typename T>
>>> const T & min(const T & a , const T & b)
>>> {return (a < b ? a : b );}
>>> template<typename T>
>>> const T & max(const T & a , const T & b)
>>> {return (a < b ? b : a );}
>>> template int max(int,int);

>> template<> int max(int,int);
>>

> Hi Ian
>
> After using following way of expilicit Instantiation ....compilation
> Error goes
> But i donot find Symbol w.r.t. function's in my Object File...
>
> Currently i am using gcc version 3.2.3
>
> template<int,int> int max(int,int);
> template<int,int> int min(int,int);
>

These aren't specialisations.

The specialisations would be declared as

template<> const int& max( const int&, const int&);
template<> const int& min( const int&, const int&);

and will have to be defined somewhere in your application.

--
Ian Collins.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
template class instantiate without template parameter, automatic type deduction Fei Liu C++ 4 10-26-2007 02:39 PM
template class instantiate without template parameter, automatictype deduction Fei Liu C++ 0 10-25-2007 08:12 PM
Inability to explicitly specialize a template class within another non-specialized template class jn@ngedit.com C++ 1 02-17-2006 07:17 PM
Out-of-class definition of a non-template member of an explicitly specialized class template? BigMan C++ 3 04-22-2005 06:28 AM
Template ctor - explicitly specify templ param Agoston Bejo C++ 1 01-03-2005 08:46 AM



Advertisments