473,739 Members | 4,265 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Friending an inner class to a templated class

I'm making progress on mixing templates with friends (sounds like a
drinking game, huh?). Anyway, here's the situation. I've got an "Outer"
class with a private "Inner" class (sub-class, technically). I want to
declaring an unrelated "Thing" class to be a friend of the inner class.
However, since the inner class is private, the compiler complains.
Here's what the code looks like:
=============== =============== =============== =======
template<typena me Tclass Thing;

class Outer {
private:
class Inner {
public: friend class Thing<Outer::In ner>;
private: int x;
};
};

template<class Thing<Outer::In ner{ static void go() { Outer::Inner
i; } };
=============== =============== =============== =========

So even though the friend statement should make the Inner class
accessible to class Thing, the compiler complains that Outer::Inner is
private, and thus inaccessible. Any ideas on how to make it work?

Thanks in advance,
--Steve (mr************ @hotmail.com)

Nov 7 '06 #1
1 1616
mrstephengross wrote:
I'm making progress on mixing templates with friends (sounds like a
drinking game, huh?). Anyway, here's the situation. I've got an
"Outer" class with a private "Inner" class (sub-class, technically).
I want to declaring an unrelated "Thing" class to be a friend of the
inner class. However, since the inner class is private, the compiler
complains. Here's what the code looks like:
=============== =============== =============== =======
template<typena me Tclass Thing;

class Outer {
private:
class Inner {
public: friend class Thing<Outer::In ner>;
private: int x;
};
};

template<class Thing<Outer::In ner{ static void go() { Outer::Inner
i; } };
=============== =============== =============== =========

So even though the friend statement should make the Inner class
accessible to class Thing, the compiler complains that Outer::Inner is
private, and thus inaccessible. Any ideas on how to make it work?
To let your 'Thing<Outer::I nner>' access 'Outer::Inner', it has to be
a friend of 'Outer', not of 'Outer::Inner'. You just gave your template
specialisation access to the 'x' variable. You didn't give access to
the 'Inner' type.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 7 '06 #2

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

Similar topics

3
6576
by: tirath | last post by:
Hi all, I have a templated class that derives from a non-templated abstract class. How do I then cast a base class pointer to a <templated> derived class pointer in a generalised fashion? Here's what I'm generally trying to achieve: I'm building (trying to anyway) a serialization library. Here's my design:
1
3342
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...
4
1524
by: Tomas Ukkonen | last post by:
Hi I'm currently trying to make my old code to compile with new gcc 3.4.0. It compiles correctly in 3.3.3 so I'm not sure if this is compiler bug or not. Code very close to a example below fails to compile because gcc 3.4.0 complains: "error: expected a type got 'Y<T>::particle'"
2
1916
by: ferdinand.stefanus | last post by:
Hi, I have some questions regarding templated class constructor: #include <iostream> using namespace std; template<typename T> class Foo { public:
9
2317
by: Jon Wilson | last post by:
I have a class which needs to accumulate data. The way we get this data is by calling a member function which returns float on a number of different objects of different type (they are all the same type for a given instance of the class, but different types for different instances.) #include<set> using namespace std; template<class T>
4
1867
by: Lionel B | last post by:
Greetings, The following code: <code> template<typename T> class A { protected:
3
2920
by: toton | last post by:
Hi, I want to specialize template member function of a template class . It is creating some syntax problem .... Can anyone say how to do it ? The class is something like this template<typename T,typename Alloc = std::allocator<T class CircularBuffer4 { public: typedef typename CircularBuffer<T,Alloc>::size_type
5
2138
by: GCRhoads | last post by:
I have some templated functions and I want to write a call wrapper class for it. I also want to pass the function object from this class to some functions that will then call the function (forwarded through my class object to the real function). I've looked around for sources on how to do this but I can't find anything. How do you do this? I would also appreciate any references to good sources about this topic if you have any. ...
5
2452
by: Daniel T. | last post by:
The goal is to make a friend function of an inner template class... template < typename T > class Foo { public: class Bar { friend bool operator==( const typename Foo<T>::Bar& lhs, const typename Foo<T>::Bar& rhs); }; };
0
9479
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
9337
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
9266
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,...
1
6754
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
6054
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
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3280
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
2748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
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.