473,394 Members | 1,721 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,394 software developers and data experts.

Template class as friend

Dear all,
ist it possible to have a template class or func as friend of other class:
Folowing returns syntax errors
template< typename T> class test{};

template< typename T> int func (Ta);

class A{

friend class test;

friend int func (???);

}



Feb 26 '06 #1
2 969
Boni wrote:
Dear all,
ist it possible to have a template class or func as friend of other
class: Folowing returns syntax errors
template< typename T> class test{};

template< typename T> int func (Ta);

class A{

friend class test;

friend int func (???);

}


It depends. Do you want all instantiations of the template to be friends of
A, or just a particular instantiation?

If you want all instantiations::

template <class T> friend int func(T a);
template <class T> friend class test;

If you want just a particular instantiation:

friend class test<A>; // ... or whatever instantiation you want
friend int func<A>(A a); // ... as above

-cd

Feb 26 '06 #2
Thanks a lot.
"Carl Daniel [VC++ MVP]" <cp*****************************@mvps.org.nospam >
schrieb im Newsbeitrag news:uC**************@TK2MSFTNGP12.phx.gbl...
Boni wrote:
Dear all,
ist it possible to have a template class or func as friend of other
class: Folowing returns syntax errors
template< typename T> class test{};

template< typename T> int func (Ta);

class A{

friend class test;

friend int func (???);

}


It depends. Do you want all instantiations of the template to be friends
of A, or just a particular instantiation?

If you want all instantiations::

template <class T> friend int func(T a);
template <class T> friend class test;

If you want just a particular instantiation:

friend class test<A>; // ... or whatever instantiation you want
friend int func<A>(A a); // ... as above

-cd

Feb 27 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Bonzo | last post by:
I'm trying to write a class for a smart pointer. I'm having a problem though when trying to implement operator== with both sides being a Smart. (Or any function that I try to bring U into.) The...
2
by: Christophe Barbe | last post by:
I am not clear about friend functions of a template class. GCC (3.3.2) wants me to add <> after the friend function names in the class declaration and VisualC++ doesn't like that. template...
2
by: Christophe Barbe | last post by:
I posted a few days ago about the same problem but was not very clear. So here is my second take at it. Basically with GCC 3.3.2, I can't compile the example from the C++ FAQ Lite available...
1
by: Oplec | last post by:
Hi, I'm learning C++ as a hobby using The C++ Programming Language : Special Edition by Bjarne Stroustrup. I'm working on chpater 13 exercises that deal with templates. Exercise 13.9 asks for me...
1
by: Dmitry D | last post by:
Hi all, I'm having problems with declaring a template friend function. It seems like I've done everything as explained in C++ FAQ, but still, I'm getting the linker error (unresolved external...
5
by: Trevor Lango | last post by:
What is the appropriate syntax for placing a friend function that includes as one of it's parameters a pointer to the class object itself within the template class? I have the following: ...
6
by: Ben Ingram | last post by:
Hi all, I am writing a template matrix class in which the template parameters are the number of rows and number of columns. There are a number of reasons why this is an appropriate tradeoff for...
6
by: Adam Parkin | last post by:
Hello, all I'm having a problem with friend functions in a templatized Queue class I'm writing using linked lists. The problem is that I can't get the friend function to be able to access private...
9
by: Adam Badura | last post by:
I have code like this template<int size> big_int { /* ... */ template<int size2> friend class big_int<size2>; }; What I wanted to achive is to be able to easly convert different sized...
3
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and...
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: 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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.