template in a template specialization

This is a discussion on template in a template specialization within the C++ Programming forums, part of the General Programming Boards category; HI all I am having trouble in specializing the class below Code: template< class TPA > public TClass{ template< class ...

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    6

    template in a template specialization

    HI all
    I am having trouble in specializing the class below
    Code:
    template< class TPA >
    public TClass{
    
               template< class TPB >
               struct Functor {
                   void Foo(){
                            // do someting
                   }
                };
    };
    I would like tomake specialization for Functor< TPB >.
    How to do that? I am trying the code blow but it doesn' work

    Code:
    // specialization for Functor inside generic TClass< TPA >
    template< class TPA >
    void TClass< TPA >::Functor< int >::Foo(){
        // do something else
    }
    Thanks
    Mn

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,413
    Code:
    template<typename TPA> template<>
    void TClass<TPA>::Functor<int>::Foo()
    {
    // My code
    }
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Jul 2009
    Posts
    6
    Hi,

    I realized that I wrote not the correct code
    Code:
    template< class TPA >
    public TClass{
               template< class TPB >
               struct Functor {
                   void Foo( TPA obj_1 , TPB obj_2 ){
                            // do someting wotj obj1 and obj2
                   }
                };
    };
    
    /// specialization for Functor inside generic TClass< TPA >
    template< class TPA >
    void TClass< TPA >::Functor< int >::Foo( TPA, int ){
        // do something else
    }
    I tried and I have this
    error: invalid explicit specialization before ‘>’ token
    error: enclosing class templates are not explicitly specialized
    error: no member function ‘operator()’ declared in ‘TClasst<_MyClass>::Mutator< int>::Foo()’
    Last edited by manustone; 09-04-2009 at 04:37 AM.

  4. #4
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Code:
    "ComeauTest.c", line 13: error: a template declaration containing a template
              parameter list may not be followed by an explicit specialization
              declaration
      template<typename TPA> template<>
                                      ^
    
    "ComeauTest.c", line 14: error: partial specialization of nontype
              "TClass<TPA>::Functor<TPB>::Foo [with TPB=int]" is not allowed
      void TClass<TPA>::Functor<int>::Foo()
    Probably the simplest way would be not to use nested classes.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  5. #5
    Registered User
    Join Date
    Jul 2009
    Posts
    6
    Thanks man!
    Mn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. Template specialization
    By CornedBee in forum C++ Programming
    Replies: 2
    Last Post: 11-25-2003, 01:02 AM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 11:54 AM

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