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

Friending an inner class to a templated class

P: n/a
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<typename Tclass Thing;

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

template<class Thing<Outer::Inner{ 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
Share this Question
Share on Google+
1 Reply


P: n/a
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<typename Tclass Thing;

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

template<class Thing<Outer::Inner{ 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::Inner>' 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 discussion thread is closed

Replies have been disabled for this discussion.