getting Error :: explicitly instantiate functional Template

P

Pallav singh

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
 
I

Ian Collins

Pallav said:
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);
 
P

Pallav singh

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);
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
 
I

Ian Collins

Pallav said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top