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 >:o;
( 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 >:o
referenced from B< char >:o.
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
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 >:o;
( 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 >:o
referenced from B< char >:o.
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