473,395 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to make Template functions friends to a class

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
2 1156
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Sebastian Faust | last post by:
Hi, is a construction like the following possible: template<class view_model> class template_clase { protected: template_clase() {} virtual ~template_clase() {}
10
by: william xuuu | last post by:
Actually, I also got linker errors with template functions and template classes. And I avoided both of them successfully, by pouring foo.cpp into foo.h, according to the C++ FAQ. ...
7
by: Leon | last post by:
I'm having a bit of a template-problem, and I was wondering if you guru's know what I'm doing wrong here... I want to create a Vertex class that supports a toPoint() method. Now, in my case...
0
by: Chris F Clark | last post by:
In our C++ project we have some internal bug reporting macros that we use to get useful information when the program does something unexpected. Essentially at the point of the error, we invoke an...
8
by: Exits Funnel | last post by:
Hello, I've been tasked with porting some C++ code from Windows to Linux. The following excerpt is giving me trouble: //BEGIN CODE #include <string> class TempTestBase_t {
2
by: franklini | last post by:
hello people i. can anybody help me, i dont know what is wrong with this class. it has something to do with the me trying to override the input output stream. if i dont override it, it works fine....
15
by: Nick Keighley | last post by:
Hi, I found this in code I was maintaining template <class SingletonClass> SingletonClass* Singleton<SingletonClass>::instance () { static SingletonClass _instance; return &_instance; }
9
by: neildferguson | last post by:
I am using templates with a little project I am working on. My compiler (GCC) is finding a particular construct ambiguous. Can anyone suggest something I might change in the declaration of class...
3
by: laikon | last post by:
this question is about how to define friend functions for a class template. the following is an example. template <typename T> class Array { private: T* parr; int sz;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.