Scope resolution in needed to call a functor maker

Discussion in 'C++' started by Howard Gardner, Feb 5, 2005.

  1. /*
    I don't have to provide scope resolution in sit 0 below: adl
    finds the function that I mean to use.

    I do have to provide scope resolution in sits 1 and 2.

    Can anyone teach me a trick to get around the need for scope resolution
    in sit 1 or sit 2?

    sit 1 is my motivating case, but if there's a trick for sit 2 I'd like
    to know it too.

    #include <iostream>
    using namespace std;

    // minimalist functor
    template < typename xCallable, typename xResult >
    struct ftor
    typedef xCallable tCallable;
    typedef xResult tResult;
    ftor(const ftor & fThat):cCallable(fThat.cCallable){}
    explicit ftor(tCallable fCallable):cCallable(fCallable){}
    template < typename xArg > tResult operator()(xArg fArg) const
    {return cCallable(fArg);}
    tCallable cCallable;

    // functor maker
    template < typename xResult, typename xArg >
    ftor< xResult (*)(xArg), xResult >
    make_ftor(xResult (*fPtrFunc)(xArg))
    {return ftor< xResult (*)(xArg), xResult >(fPtrFunc);}

    // class and function that uses it
    namespace A
    class a{};
    a func(a fA){cout << "::A::func" << endl; return fA;}

    int main()
    typedef A::a tA;
    typedef tA (*tPtrFunc)(tA);

    tA fA;

    // sit 0 - Finds through adl

    // sit 1 - Insists on scope resolution

    // sit 2 - Insists on scope resolution
    tPtrFunc fPtrFunc = A::func;
    Howard Gardner, Feb 5, 2005
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.