Thread: struct inside a class

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    struct inside a class

    Hello everyone,


    For the MSDN sample,

    http://msdn2.microsoft.com/en-us/library/2af6btx2.aspx

    Code:
      template <class U>
          struct rebind { typedef stingyallocator<U> other; };
    My question is, what is the purpose of defining an internal struct which has only a type? How to use it? Why class U is different from _Ty?

    (I see similar code in STL internal implementation for allocator class, seems like a pattern which I do not know.)


    thanks in advance,
    George

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Ah, the rebind mechanism. Welcome to the dark secrets of the STL.

    Allocators are very complex, and rebind is a part of that. You should get this information from a book.
    All the buzzt!
    CornedBee

    "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
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks CornedBee,


    I find the link,

    http://msdn2.microsoft.com/en-us/lib...ek(VS.80).aspx

    So, I think the purpose of this pattern is to change the template parameter (input type parameter to outer struct) to another one?

    Quote Originally Posted by CornedBee View Post
    Ah, the rebind mechanism. Welcome to the dark secrets of the STL.

    Allocators are very complex, and rebind is a part of that. You should get this information from a book.

    regards,
    George

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Yes, correct.
    All the buzzt!
    CornedBee

    "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

  5. #5
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks CornedBee,


    Question answered. :-)

    Quote Originally Posted by CornedBee View Post
    Yes, correct.

    regards,
    George

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to copy a C struct to a C++ class?
    By Ptbamboo in forum C++ Programming
    Replies: 1
    Last Post: 02-21-2009, 02:11 PM
  2. Replies: 3
    Last Post: 10-31-2005, 12:05 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 06:58 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM