Template function specialization

This is a discussion on Template function specialization within the C++ Programming forums, part of the General Programming Boards category; Hi folks. The following code compiles fine with icc, however g++-3.3 issues "12: parse error before ';' token". What's wrong? ...

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    3

    Template function specialization

    Hi folks.
    The following code compiles fine with icc, however g++-3.3 issues "12: parse error before ';' token". What's wrong?

    Code:
    /*
     * simple test case for nested templates and template function specialization
     */
    
    # include <iostream>
    
    using std::cout;
    using std::endl;
    
    /**
     * Class template
     */ 
    template< class T, int pT >
    class A 
    {
      public:
        static void function()
        {
            T::function< pT >(); // g++ does not like this line
        }
    };
    
    /*
     * Class with function template
     */
    class B
    {
      public:
        template< int pT > 
        static void function();
    };
    
    /*
     * For some reason, template function specialization may not occur in class definitions
     */
    template< int pT > void B::function()
    {
        cout << "unspecialized" << endl;
    }
    
    template< > void B::function< 0 >()
    {
        cout << "specialized" << endl;
    }
    
    
    /*
     * Typedef to fake template function specialization in a class template
     */
    typedef A< B, 0 > C;
    
    /*
     * Putting it all together
     */
    class D
    {
      public:
        static void function()
        {
            C::function();
        }
    };
    
    
    int main() {
    
        D::function();
    
        return 0;
    }

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    148
    Code:
    template< class T, int pT >
    class A 
    {
    public:
    	static void function()
    	{
    		T::template function< pT >(); //Now he likes it ;)
    	}
    }

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    3
    Thank you so much

    BTW - where does one get that syntactic knowledge? I've been looking in Stroustrup 3rd Ed and Deitel and Deitel 3rd Ed and I could not find anything in either book.

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    148
    >>BTW - where does one get that syntactic knowledge?
    >>I've been looking in Stroustrup 3rd Ed
    The C++ Programming Language,Bjarne Stroustrup 3rd Edition , Page 922 in the German Edition.
    Chapter C.13.6.

  5. #5
    Registered User
    Join Date
    Jun 2003
    Posts
    3
    Danke, hab's jetzt in meiner englischen Version tatsaechlich auch gefunden.

    Peinlich, peinlich.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  2. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 12:03 PM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21