friend access from nested class

C

Chris Schadl

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
 
S

Siemel Naran

Chris Schadl said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top