Skip to main content
gamedev.net
🔒 Locked

friend template classes

Started by Noodles Aug 29, 2000 at 9:48 AM 0 replies 450+ views
Original Post
Noodles
Noodles
Im using templates to make a generic linked list i have one class template called ListElement which contains data the data and and the pointer to the next ListElement, and a template class called List which contains an object of type ListElement. I want the data in ListElement to be private, so how do i tell that List is a friend of ListElement?
Kensai
Kensai
Well, this works:

template< class T > class foo_list;

template< class T > class foo {
friend foo_list;
};

template< class T > class foo_list (

};


However what I would do would be to declare ListElement (foo, in the above example) as an inner class of List, ie:


template< class T >
class List
{
template< class T >
class ListElement
{
friend List;
};
};


Edited by - Kensai on August 29, 2000 3:36:28 PM

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.