By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,402 Members | 1,117 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,402 IT Pros & Developers. It's quick & easy.

How to make Template functions friends to a class

P: n/a
Can we declare a template function as a friend to a class, if yes
please give me the syntax.Thanks in advance
rgrds
Madhukar
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 5 Feb 2004 02:46:27 -0800 in comp.lang.c++, ma********@yahoo.com
(madhukar_bm) was alleged to have written:
Can we declare a template function as a friend to a class, if yes


This issue is covered in Marshall Cline's C++ FAQ. See the topic
"[34.15] Why do I get linker errors when I use template friends?" It
is always good to check the FAQ before posting. You can get the FAQ at:
http://www.parashift.com/c++-faq-lite/
Jul 22 '05 #2

P: n/a
madhukar_bm wrote:
Can we declare a template function as a friend to a class, if yes
please give me the syntax.Thanks in advance
rgrds
Madhukar


Yes.

class foo
{
public:
template <typename x> friend class x;
int y;
};
template <typename x> class x
{
public:
void func( foo * x )
{
x->y =2;
}
};
I didn't compiler the code above but it *should* work.

Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.