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 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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Christopher Benson-Manica |
last post by:
#include <vector>
class Bar;
class Foo
{
friend class Bar; /* 1 */
protected:
int myint;
|
by: Mark P |
last post by:
Is this legal and sensible?
class Outer
{
friend struct Inner
{
...
};
...
|
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
|
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...
|
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;
| |
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 {
|
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;
}
|
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>
|
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>
|
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...
|
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...
| |
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |