I am porting some code to XCode 2.4, and I’m having
trouble getting a template function to compile. It works in other
compilers; MSVC, Codewarrior, and Intel C++.
Below is a simplified example illustrating the
situation. I have a static template member function in a template class,
and I’m attempting to call it in a global template function.
Oddly, I get the compile error even though I’m not
instantiating the global function.
Is this a problem with GCC or with me? Any advice for
a workaround?
Thanks for any help.
Best regards,
Finley Lee
Alien Skin Software
/// Example begins here
#include <iostream>
template < typename T >
class template_class
{
public:
static T member_fn(
T in ) { return T(4) ; }
template <
typename R >
static R
template_member_fn( T in ) { return (R) T(3.1) ; }
} ;
template < typename U,
typename V >
void do_stuff( U first, V second
)
{
// ok
std::cout <<
"template_class<U>::member_fn( first ) == " <<
template_class<U>::member_fn( first ) << std::endl ;
// not ok - error:
expected primary-_expression_ before 'double'
std::cout <<
"template_class<U>::template_member_fn<double>( first ) ==
" << template_class<U>::template_member_fn<double>(
first ) << std::endl ;
// not ok - error:
expected primary-_expression_ before '>' token
std::cout <<
"template_class<U>::template_member_fn<V>( second ) == "
<< template_class<U>::template_member_fn<V>( first ) <<
std::endl ;
}
int main (int argc, char * const
argv[])
{
// ok
std::cout <<
"member_fn( 3 ) == " << template_class<int>::member_fn( 3
) << std::endl ;
// ok
std::cout <<
"template_class<int>::template_member_fn<double>( 2.1 ) ==
" << template_class<int>::template_member_fn<double>(
2.1 ) << std::endl ;
return 0;
}