473,657 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Template friend can't be template parameter


Does anyone know the wisdom behind this ?

I want to make a template whose parameter needs to be a friend.

What's the right(TM) way to do this ?

template <typename T, typename TF>
class Boo
{
friend class TF; // error: using template type
// parameter `TF' after `class'

friend TF; // error: template parameters cannot be friends

template <typename TF2>
class Obfuscator
{
public:

typedef TF2 ObfusType;
};

// the following seems to work for GCC but not MSVC
friend class Obfuscator<TF>: :ObfusType;

public:

T value;
};
class Tester
{
public:

Tester()
{
Boo< int, Tester > x;

x.value = 1;
}

};

Jul 19 '05 #1
1 3168
On 05 Sep 2003 01:45:20 GMT, Gianni Mariani <gi*******@mari ani.ws>
wrote:

Does anyone know the wisdom behind this ?

I want to make a template whose parameter needs to be a friend.

What's the right(TM) way to do this ?


There isn't a right way - it is forbidden by 11.4/2 which says that an
elaborated-type-specifier shall be used in a friend declaration for a
class.

For a detailed answer,
http://makeashorterlink.com/?F24766EC5

Tom
Jul 19 '05 #2

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

Similar topics

4
5551
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 pointer contained might not be the exact same type but still get tested for equality. Here's what I have: template <typename T> class Smart; template<typename T, typename U>
2
12522
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 <class T> class test{ test(void); ~test(void); friend bool operator== <> (const test<T> &p1, const test<T> &p2); }
1
3335
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 to turn a previously made String class that deals with char's into a templated String class that uses the template parameter C instead of char. I thought it would be fairly simple to do this exercise, but I encoutered many errors for my...
5
1638
by: Gianni Mariani | last post by:
The code below compiles on gcc 3.4.0 and Comeau's 4.3.3 but MSVC++ 7.1 dies complaining about somthing <unknown>. Is this valid ? More to the point, is there any way of doing this that is supported across all 3 compilers ? I want a template to take a parameter and make it it's friend. <code>
4
2440
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 far is pretty simple: using an idea of Andrei Alexandrescu (at least that's where I first read it) to create a lightweight way of overloading member functions since member function specialization is not possible.
5
2627
by: Ruben Campos | last post by:
Some questions about this code: template <typename T> class MyTemplate; template <typename T> MyTemplate <T> operator- (const MyTemplate <T> & object); template <typename T> MyTemplate <T> operator- (const MyTemplate <T> & object1, const MyTemplate <T> & object2); template <typename T> class MyTemplate
13
1740
by: Atlas | last post by:
Hi, I implemented a template as: template <int L, int M, int T> class Quantity { ..... public: friend Quantity operator*(const Quantity& q1,const Quantity& q2); ..... };
5
1291
by: John Harrison | last post by:
Why isn't this legal code and is there any other way to achieve the effect I want (i.e. make a template parameter the friend of a template class). template <class X> class I { friend class X; private: I() {}
9
3729
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 big_int's and to operate on them. But for this I need to be able to access private data of big_int. The problem is that for differenc sizes this are of
0
8842
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8740
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8516
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8617
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.