Is there aA correct way of specializing member functions of template classes?

Discussion in 'C++' started by m0shbear, Mar 1, 2011.

  1. m0shbear

    m0shbear Guest

    Suppose I have the following:
    foo.h--
    template <class T>
    class Foo {
    T bar(const T&);
    };

    foo.cpp--
    #include "foo.h"
    int Foo<int>::bar(const int& x) {
    ....
    return ...;
    }

    The compile fails with " error: too few template-parameter-lists" (g++
    4.5).

    Is there a correct way to properly specialize such member functions?
    As there is a small, finite set of T to be used, I want to specialize
    for all T.
    m0shbear, Mar 1, 2011
    #1
    1. Advertising

  2. m0shbear

    Nobody Guest

    On Mon, 28 Feb 2011 21:30:14 -0800, m0shbear wrote:

    > int Foo<int>::bar(const int& x) {
    > ...
    > return ...;
    > }
    >
    > The compile fails with " error: too few template-parameter-lists" (g++
    > 4.5).
    >
    > Is there a correct way to properly specialize such member functions?


    template<>
    int Foo<int>::bar(const int& x) {
    Nobody, Mar 1, 2011
    #2
    1. Advertising

  3. m0shbear

    Paul Guest

    "m0shbear" <> wrote in message
    news:...
    > Suppose I have the following:
    > foo.h--
    > template <class T>
    > class Foo {
    > T bar(const T&);
    > };
    >
    > foo.cpp--
    > #include "foo.h"
    > int Foo<int>::bar(const int& x) {
    > ...
    > return ...;
    > }
    >
    > The compile fails with " error: too few template-parameter-lists" (g++
    > 4.5).
    >
    > Is there a correct way to properly specialize such member functions?
    > As there is a small, finite set of T to be used, I want to specialize
    > for all T.
    >


    AFAIK you cannot specialise the member function without specialising the
    whole class.
    ..
    Paul, Mar 1, 2011
    #3
    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.
Similar Threads
  1. Jeff
    Replies:
    2
    Views:
    412
  2. Simon G Best
    Replies:
    2
    Views:
    552
    Simon G Best
    Dec 29, 2006
  3. Rahul
    Replies:
    8
    Views:
    385
    Lionel B
    Jul 16, 2007
  4. Hicham Mouline
    Replies:
    0
    Views:
    418
    Hicham Mouline
    Apr 23, 2009
  5. Hicham Mouline
    Replies:
    1
    Views:
    403
    Michael DOUBEZ
    Apr 24, 2009
Loading...

Share This Page