Thread: Template Partial Specialization

  1. #1
    Registered User
    Join Date
    May 2006

    Template Partial Specialization

    Hello everyone,

    About Template Partial Specialization,

    sometimes in real case like below,

    there will be two definitions at the same time,

    template <typename T>
    class Foo {
    template <typename T>
    class Foo <T *>
    In theory, compiler will match the latter one with first priority compared with the 1st one.

    My question is, I tihnk for basic data types it is easy to match,


    when we pass Foo <int*>, the latter one is matched and T is int. But for arbitrary data types, like used data types, how could compiler judge whether a type is pointer (when the latter template class should be matched) or not a pointer (when the first template class should be matched).

    thanks in advance,

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    For arbitrary data types, it's still a pointer if it's a pointer, and not a pointer if it's not. Smart pointers don't count.
    All the buzzt!

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Portland, OR
    The compiler obviously knows if a type is a pointer type. There is no confusion here. The most specialized template wins.

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. Partial specialization of class template.
    By CornedBee in forum C++ Programming
    Replies: 4
    Last Post: 11-20-2003, 09:24 AM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 12:54 PM