getting Error :: explicitly instantiate functional Template

Discussion in 'C++' started by Pallav singh, Sep 15, 2008.

  1. Pallav singh

    Pallav singh Guest

    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
     
    Pallav singh, Sep 15, 2008
    #1
    1. Advertising

  2. Pallav singh

    Ian Collins Guest

    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.
     
    Ian Collins, Sep 15, 2008
    #2
    1. Advertising

  3. Pallav singh

    Pallav singh Guest

    On Sep 15, 1:16 pm, Ian Collins <> 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
     
    Pallav singh, Sep 15, 2008
    #3
  4. Pallav singh

    Ian Collins Guest

    Pallav singh wrote:
    > On Sep 15, 1:16 pm, Ian Collins <> 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.
     
    Ian Collins, Sep 15, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page