Template Class as a friend of another class

This is a discussion on Template Class as a friend of another class within the C++ Programming forums, part of the General Programming Boards category; What is the correct/best way to include a template class within another class? Thanks. I have the following: Code: template ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    55

    Template Class as a friend of another class

    What is the correct/best way to include a template class within another class? Thanks.

    I have the following:

    Code:
    template <typename HashedObj>
    class HashTable
    {
      ...and want to include it in another class:
    Code:
    class DisjointSets
    {
      public:
                friend class HashTable;     //This does not work
       ...

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    No, you will need to give a type for the HashTable you want to keep as a friend.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,235
    Code:
    template <typename T> friend class HashTable;
    This makes all implementations of HashTable<> a friend.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with friend class declaration in a namespace
    By Angus in forum C++ Programming
    Replies: 2
    Last Post: 12-09-2008, 12:29 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Instantiating a template class
    By NullS in forum C++ Programming
    Replies: 11
    Last Post: 02-23-2005, 09:04 AM
  4. Template specialization
    By CornedBee in forum C++ Programming
    Replies: 2
    Last Post: 11-25-2003, 01:02 AM
  5. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 07:26 PM

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