• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Template Compile Problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Template Compile Problem


  • Subject: Template Compile Problem
  • From: "Finley Lee" <email@hidden>
  • Date: Tue, 12 Sep 2006 12:24:07 -0400
  • Thread-topic: Template Compile Problem

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;

}

 

 

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Template Compile Problem
      • From: Andreas Grosam <email@hidden>
  • Prev by Date: Re: Simple way to indicate activity?
  • Next by Date: Re: Simple way to indicate activity?
  • Previous by thread: Re: Simple way to indicate activity?
  • Next by thread: Re: Template Compile Problem
  • Index(es):
    • Date
    • Thread