Template Friends

This is a discussion on Template Friends within the C++ Programming forums, part of the General Programming Boards category; Okay. This will sound like a funny question, or at least it was funny when it occurred to me that ...

  1. #1
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856

    Template Friends

    Okay. This will sound like a funny question, or at least it was funny when it occurred to me that I've never thought about how to do what I'm trying to do, but...

    I've got a base class A from which 2 classes are derived B : A and C : A. Class B is a template and C is a pure virtual. The only template parameter for B is any object derived from C. Keeping it straight? Okay, let's continue...

    Now, there are functions I need private in C, but that need to be called by B. The best logical solution is to make B a friend of C (which it should be anyway), but I have no idea if/how a class might make a template class its friend.

    Have you any idea?

  2. #2
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    Ahh.. I've got it. The syntax is:
    Code:
    class C : public A {
      template <typename T>
      friend class B;
    };

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Specialising a member function with a template template parameter
    By the4thamigo_uk in forum C++ Programming
    Replies: 10
    Last Post: 10-12-2007, 04:37 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  4. Friends in a template class
    By dalek in forum C++ Programming
    Replies: 2
    Last Post: 09-19-2004, 09:10 PM
  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