Thread: Friend template functions

  1. #1
    Amateur
    Join Date
    Sep 2003
    Posts
    228

    Friend template functions

    Hello everybody!

    Today, I have a question; it is maybe simple but I couldn't figured it out or a long time, so, perhaps could you help.
    It is: How do you declare a friend template function inside of a class?

    Thanks

  2. #2
    Registered User
    Join Date
    Oct 2002
    Posts
    22

    Not sure if this is what you want..

    All you have to do is declare teh function with the keyword friend infront of it....
    Code:
    class two;               // needed for frifunc declaration
    
    class one
    {
         private:
             int data;
         public:
              one() : data(3)
              {}
              friend int friefunc(one, two);         //friend function
    
    };
    
    class two
    {
           private:
              int data;
           public:
              beta() : data(7)
              {}
              friend int frifunc(one, two);           //friend function
    };
    I hope this helps...

  3. #3
    Amateur
    Join Date
    Sep 2003
    Posts
    228
    Well, I was speaking about template friend functions.

  4. #4
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    I believe this is the proper way to declare a template friend function.
    Code:
    template <class data_type>
    friend func(data_type d);
    While you're breakin' down my back n'
    I been rackin' out my brain
    It don't matter how we make it
    'Cause it always ends the same
    You can push it for more mileage
    But your flaps r' wearin' thin
    And I could sleep on it 'til mornin'
    But this nightmare never ends
    Don't forget to call my lawyers
    With ridiculous demands
    An you can take the pity so far
    But it's more than I can stand
    'Cause this couchtrip's gettin' older
    Tell me how long has it been
    'Cause 5 years is forever
    An you haven't grown up yet
    -- You Could Be Mine - Guns N' Roses

  5. #5
    Amateur
    Join Date
    Sep 2003
    Posts
    228
    Oh, that simple... Thanks & sorry to ask silly things.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Implementation of a template class functions
    By 39ster in forum C++ Programming
    Replies: 3
    Last Post: 01-08-2008, 03:36 AM
  2. 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
  3. Template specialization
    By CornedBee in forum C++ Programming
    Replies: 2
    Last Post: 11-25-2003, 02:02 AM
  4. inline friend functions.
    By sean in forum C++ Programming
    Replies: 2
    Last Post: 01-03-2002, 12:37 PM
  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