pointer to memb func not enough for implicit instantiation?

Discussion in 'C++' started by Francesco, Sep 11, 2008.

  1. Francesco

    Francesco Guest

    Hi to all,

    The code below is a ( very ) simplified example of the problem I'm
    facing.

    // CODE
    template< typename T >
    class A
    {
    public:
    void Do() {}
    };

    template< typename T >
    class B
    {
    public:
    void Do()
    {
    A< int > obj;
    void ( A< int >::*pmf )() = &A< int >::Do;
    ( obj.*pmf )();
    // pmf not sufficient to instantiate memb func?
    //return; A< int >().Do(); // WITH THIS IT LINKS
    }

    };

    int main()
    {
    B< char > obj;
    obj.Do();
    }
    // END CODE

    This compiles fine but does not link: missing symbol A< int >::Do
    referenced from B< char >::Do.
    Basically it seems that a pointer to a member function of a template
    class, referenced from a member function of another template class is
    not enough to instantiate the first member function.

    I've tried to take a look at the standard [temp.inst] 14.7.1 and it
    says
    "Unless a member of
    a class template or a member template has been explicitly instantiated
    or explicitly specialized, the specialization of the
    member is implicitly instantiated when the specialization is
    referenced in a context that requires the member de├»┬Čnition
    to exist"

    My naive interpretation is that the code above should work...

    I'm using GCC 4.0 on XCode 3.1 (Mac OS X). I was wondering if there is
    a compiler option that forces instantiation in cases like this...

    Probably I'm missing something.... any help, suggestion or advice
    would be greatly appreciated ( as usual...)
    Thanks in advance,
    Francesco
     
    Francesco, Sep 11, 2008
    #1
    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. CRON
    Replies:
    24
    Views:
    202,063
    Adrienne Boswell
    Jun 20, 2006
  2. Johnny
    Replies:
    3
    Views:
    470
    Robert Kern
    Aug 23, 2005
  3. Hari Sekhon
    Replies:
    0
    Views:
    528
    Hari Sekhon
    Jun 20, 2006
  4. Vinko Vrsalovic

    int func() v/s int func(void)

    Vinko Vrsalovic, Jan 21, 2005, in forum: C Programming
    Replies:
    14
    Views:
    1,350
    Villy Kruse
    Jan 24, 2005
  5. jimjim
    Replies:
    16
    Views:
    855
    Jordan Abel
    Mar 28, 2006
Loading...

Share This Page