473,326 Members | 2,061 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,326 software developers and data experts.

template/friend problem

frs
How can I get a template friend?

I want to achieve something like the subsequent two cases:

(1) class A {
template <typename T> friend class T;
};

(2) template <typename T>
class A {
friend class T;
};

Thanks,

Frank

Sep 4 '05 #1
4 4732
frs wrote:
How can I get a template friend?

I want to achieve something like the subsequent two cases:

(1) class A {
template <typename T> friend class T;
You probably meant to use the real name of the template, not
the template argument.
};

(2) template <typename T>
class A {
friend class T;
'T' is not necessarily a class.
};

Well, what do you mean exactly by "get a template friend"? What
problem are you trying to solve?

V
Sep 4 '05 #2
frs
Victor Bazarov schrieb:
Well, what do you mean exactly by "get a template friend"? What
problem are you trying to solve?


OK, this was typo! In case 1, a class B<T> shall be friend of A.
In case 2, T itself shall be a friend of A<T>. What is the syntax for
that?

frs

Sep 4 '05 #3
I want to achieve something like the subsequent two cases:

(1) class A {
template <typename T> friend class T;
};

(2) template <typename T>
class A {
friend class T;
};


I just pulled out my copy of "C++ Templates. The Complete Guide"
(excellent, trully complete, book) and read that the type represented
by the template parameter cannot be made a friend of the template
class. It also says that such mechanism will be added in the future (?)

If you want a class template B to be a friend of A, you should make A
also a class template:

template <typename T>
class A {
friend class B<T>;
};

Sep 4 '05 #4
frs wrote:
Victor Bazarov schrieb:
Well, what do you mean exactly by "get a template friend"? What
problem are you trying to solve?
OK, this was typo! In case 1, a class B<T> shall be friend of A.


class A {
template<class T> friend class B;
};
In case 2, T itself shall be a friend of A<T>. What is the syntax for
that?


That's either impossible or could be achieved with a hack only, in both
cases it's ill-advised, anyway. I think you should work around it.

V
Sep 4 '05 #5

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

Similar topics

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...
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...
2
by: Ruben Campos | last post by:
I have a problem with a template function that is declared as a friend of a template class. I'll first show the exact problem with source code: // MyClass.hpp template <typename T> class...
4
by: Justin Miller | last post by:
Ok, I tried to make that subject as descriptive as possible. What I'm trying to do: I'm attempting to use policies to create a generic memento (design pattern) template. My Memento template so...
3
by: CoolPint | last post by:
After upgrading to gcc 3.4.2 from gcc 3.2.3, I got compiler errors that I could not figure out. After reading other postings, I learned that my coding was not compliant to the standard in the first...
2
by: coolpint | last post by:
Can anyone kindly provide an explanation as to why the compiler does not "see" the function template in the contrieved code below? I think the argument deduction fails but can't figure out...
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...
4
by: Alan Woodland | last post by:
I've been trying out more template metaprogramming ideas with typelists (mostly for personal learning, I'm aware boost most probably provides this facility already), and I've run into this small...
9
by: wo3kie | last post by:
#include <iostream> #include <map> #include <utility> // // Base // / | \ // Derived1 Derived2 \ // \ | / // Derived3
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.