473,614 Members | 2,361 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

friend access from nested class

Okay, I'm having a bit of a brain-fart and I can't remember how I would do
this.

Say I have the following:

template <typename T1, typename T2> class A; // Forward declaration of A

template <typename T1, typename T2>
class B
{
private:
/* .... */
public:
friend class A<T1, T2>; // OK - B sees forward declaration of A
/* .... */
};

template <typename T1, typename T2> // Definition of A
class A
{
private:
class<T1, T2> B;
/* .... */
public:
class C { /* .... */ };
};

How do I make private members of B accessable to C? Simply adding `friend
class A<T1, T2>::C;` to class B dosen't work (my compiler complains A has
no nested class C) and I'm not entierly certian of what the correct syntax
is for a forward declaration of A::C is if A is a template class. Any
ideas?

Thanks,

Chris Schadl
Jul 22 '05 #1
1 2073
"Chris Schadl" <cs*****@satan. blah.org.uk> wrote in message
template <typename T1, typename T2> class A; // Forward declaration of A

template <typename T1, typename T2>
class B
{
private:
/* .... */
public:
friend class A<T1, T2>; // OK - B sees forward declaration of A
/* .... */
};

template <typename T1, typename T2> // Definition of A
class A
{
private:
class<T1, T2> B;
/* .... */
public:
class C { /* .... */ };
};

How do I make private members of B accessable to C? Simply adding `friend
class A<T1, T2>::C;` to class B dosen't work (my compiler complains A has
no nested class C) and I'm not entierly certian of what the correct syntax
is for a forward declaration of A::C is if A is a template class. Any
ideas?


You can't make a class a friend to a forward declared nested class, because
you can't forward declare a nested class.

You can make class A::C non-nested, and with a name like A_C.
Jul 22 '05 #2

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

Similar topics

11
1197
by: Christopher Benson-Manica | last post by:
#include <vector> class Bar; class Foo { friend class Bar; /* 1 */ protected: int myint;
7
1942
by: Mark P | last post by:
Is this legal and sensible? class Outer { friend struct Inner { ... }; ...
4
1199
by: Howard Swope | last post by:
I keep running into places in my code where I would like only a particular class of object to be able to access certain members of another class of object. In C++ the friend keyword provided this functionality. The only thing I have found in C# is internal but this is still broader in scope than I am looking for. Is there a way in C# to get the functionality of the C++ friend keyword? -- Howard Swope
3
3777
by: Mark | last post by:
Hi... Maybe I'm just being especially obtuse today, but I've been perplexed by how some of the protection levels have been working with nested classes in C#. I have a parent class that wants to be able define sub-object to return to consumers but wants to really clamp down on how much is exposed to the consumer - for example, I wanted to make consumers unable to instantiate the sub-objects on their own. Originally, i'd hoped...
1
1425
by: Joe Carner via .NET 247 | last post by:
First time posting, thanks in advance for any help you can give me. Basically I am trying to a class that i want to be able to access the private data members of another class, both of which i created. But, I can't get the friend class to work. For example (this is not actually my code): template <typename Key, typename Value> class MyMap; template <typename Key, typename Value> struct MyMapNode;
1
2119
by: Tomas Sieger | last post by:
Hi all, I'm in doubt with the following code: class Base { public: class Nested {}; }; class Derived:public Base { public: class Nested {
5
1822
by: request | last post by:
I have a little piece of code that compiles fine but I think it shouldn't compile fine. Here it is: class outer_class { public: outer_class () {} int operator () (int i1, int i2) { return i1+i2; }
3
3877
by: jdurancomas | last post by:
Dear all, I'm trying to declare the operator++ to a nested class. The nested class is not template but the container it is. The code used in teh sample program is included bellow: #include <iostream>
3
1730
by: tonvandenheuvel | last post by:
Hi all, the following code does not compile in gcc 4.0.2: 3 class Outer 4 { 5 class B; 6 7 template<typename T>
0
8179
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8621
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
8427
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
6087
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
5538
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
4119
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2565
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
1
1712
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1421
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.