Re: Friend and Templates

[ Follow Ups ] [ Post Followup ] [ CS2704 Web Discussion Board ] [ FAQ ]

Posted by William D McQuain on March 22, 2001 at 10:40:29:

In Reply to: Friend and Templates posted by Juan Romero Jr. on March 22, 2001 at 01:47:14:

: I cant remember if this topic was discussed in class or not, but I know we talked about friend functions, and we talked about templates, but what about friend functions inside templates?? Is this not allowed for this project?

It's allowed... although overloading << or >> for a container is a little warped.

: If it is, I would like to direct you all to pages 854-855 of the Stroustrop book on syntax, and how to use friend functions with templates. This is good for when you want to overload those operators that can't be used as class members (like >> and <<).

: I stumbled onto this in my code when I used a friend function with my template (and the compiler got mad at me when I coded the function header like the example given in the Operator overloading notes),

Well, yeah... the operator overloading notes don't talk about templates. But the change should be very minor.

and when I referred to the book and fixed my code, everything ran smoothly.

: My 2 cents

Follow Ups:

Post a Followup




Optional Link URL:
Link Title:
Optional Image URL:

[ Follow Ups ] [ Post Followup ] [ CS2704 Web Discussion Board ] [ FAQ ]