468,290 Members | 2,040 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,290 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
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
Sep 11 '08 #1
0 733

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.