Template function within class template not not resolving when passedfunction local class?

Discussion in 'C++' started by jrwats, Feb 28, 2010.

  1. jrwats

    jrwats Guest

    I get the following error when I try passing a local (to the function)
    class into the template function (Map) of the template class List.
    It works with external functor classes defined outside the function
    scope and Functors defined within the class template. Is there any
    way to make this work for the local classes?

    g++ -Wall Test.h -o Test
    Test.h: In member function ‘int List<T>::blah3() [with T = int]’:
    Test.h:89: instantiated from here
    Test.h:65: error: no matching function for call to ‘List<int>::Map()’
    Test.h: In function ‘int globalBlah(List<T>&) [with T = int]’:
    Test.h:90: instantiated from here
    Test.h:81: error: no matching function for call to
    ‘List<int>::Map(globalBlah(List<T>&) [with T = int]::Functor4&)’

    template <class T> // line 1
    class List
    {
    class Functor2;
    public:
    // Function template
    template <class FunctorT>
    int Map(const FunctorT& func = FunctorT());

    // Returns NULL if not found.
    int blah();
    int blah2();
    int blah3();
    };

    template <class T>
    template <class Functor>
    int List<T>::Map(const Functor& func)
    {
    return func() ? 0 : 1;
    }

    class Functor1
    {
    public:
    bool operator()() const
    {
    return true;
    }
    };

    template<class T>
    class List<T>::Functor2
    {
    public:
    bool operator()() const
    {
    return true;
    }
    };

    template<class T>
    int List<T>::blah()
    {
    return Map(Functor1());
    }

    template<class T>
    int List<T>::blah2()
    {
    return Map<Functor2>();
    }

    template<class T>
    int List<T>::blah3()
    {
    class Functor3
    {
    public:
    bool operator()() const
    {
    return false;
    }
    };
    return Map<Functor3>();
    }

    // Global template function
    template<class T>
    int globalBlah(List<T>& list)
    {
    class Functor4
    {
    public:
    bool operator()() const
    {
    return false;
    }
    };
    Functor4 f;
    return list.Map(f);
    }

    void blah()
    {
    List<int> list;
    list.blah();
    list.blah2();
    list.blah3();
    globalBlah(list);
    }
    jrwats, Feb 28, 2010
    #1
    1. Advertising

  2. Re: Template function within class template not not resolving when passed function local class?

    jrwats <> writes:

    > I get the following error when I try passing a local (to the function)
    > class into the template function (Map) of the template class List.
    > It works with external functor classes defined outside the function
    > scope and Functors defined within the class template. Is there any
    > way to make this work for the local classes?


    Not in current releases of gcc.

    This is a C++0x feature not currently available in gcc. Some compilers
    (e.g. MSVC) do support it, but gcc doesn't with the current stable
    releases.

    The gcc C++0x status page http://gcc.gnu.org/projects/cxx0x.html says
    that it is supported in the upcoming gcc 4.5 release.

    Anthony
    --
    Author of C++ Concurrency in Action http://www.stdthread.co.uk/book/
    just::thread C++0x thread library http://www.stdthread.co.uk
    Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk
    15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976
    Anthony Williams, Mar 1, 2010
    #2
    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. Itchy
    Replies:
    1
    Views:
    328
    Victor Bazarov
    Aug 12, 2003
  2. Replies:
    4
    Views:
    473
    Rob Williscroft
    Nov 18, 2004
  3. Replies:
    2
    Views:
    344
  4. Replies:
    12
    Views:
    505
    Grizlyk
    Feb 26, 2007
  5. jrwats
    Replies:
    0
    Views:
    303
    jrwats
    Feb 28, 2010
Loading...

Share This Page