By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,876 Members | 1,119 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,876 IT Pros & Developers. It's quick & easy.

friend access from nested class

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
"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 discussion thread is closed

Replies have been disabled for this discussion.