Topic: Accessing nested classes from friend functions


Author: aaron@iit.com (Aaron Emigh)
Date: 17 Aug 92 23:01:18 GMT
Raw View
I was trying to write a friend function of a template class containing
another class taking a pointer to the internal class as an argument, and
couldn't find any way to get my compiler (Borland C++ 3.0) to accept it.
I couldn't find anything clear in my documentation, so I'm wondering if
there is a defined syntax for doing this.

In case I'm not being clear, here's an example of what I mean (semantic
content has been reduced to null in the interests of brevity).

// A do-nothing template class containing only another class and a
// friend function, for demonstration purposes.

template <class type_instance_t>
class class_t {
  class internal_t {
    type_instance_t foo;
  };
  friend void frob_class (internal_t *);
};


// Here's the question: how do I declare a friend function that takes a
// class nested inside a template class as an argument?

template <class type_instance_t>
void frob_class (class_t<type_instance_t>::internal_t *arg)
{
}

For my application, declaring internal_t separately and making
class_t its friend works fine, but is less correct in terms of the
operations I am supporting.  Is there a defined way of implementing this
with the class definitions nested?

Aaron Emigh
aaron@iit.com