470,609 Members | 1,690 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,609 developers. It's quick & easy.

pointer to memb func not enough for implicit instantiation?

Hi to all,

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

template< typename T >
class A
void Do() {}

template< typename T >
class B
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;

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
"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,
Sep 11 '08 #1
0 798

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

90 posts views Thread by Mark Hahn | last post: by
12 posts views Thread by johnsolver | last post: by
9 posts views Thread by Allen | last post: by
42 posts views Thread by xdevel | last post: by
11 posts views Thread by Antoninus Twink | last post: by
19 posts views Thread by =?iso-8859-1?b?VG9t4XMg0yBoyWlsaWRoZQ==?= | last post: by
5 posts views Thread by Tim Frink | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.