pointer to memb func not enough for implicit instantiation?

F

Francesco

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
 

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

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top