www.digitalmars.com         C & C++   DMDScript  

D - Friend Declarations

Hallo NG,

As the docs say there are no friend declarations in D. But all classes 
inside the same module should be able to access private members.

Now I've got the prob that dmd says that the member functions im trying 
to use is not accessible. Both classes are inside the same module. Could 
it be a compiler bug?

The code is this

template TContainer(T)
{
class IteratorException: Exception
{
	this(char[] error){super(error);}
}
class IteratorNoNode : IteratorException
{
	this(char[] error){super(error);}
}


class Node
{
  protected:
  Node next = null, prev = null;
  T data;
  public:
  this(){}
  this(T value) {data = value;}
  this(T value, Node p , Node n )
  {
   data = value;
   prev = p;
   next = n;
  }
  T Data() {return data;}
  void Data(T value) {data = value;}

}

class List
{
  protected:
  Node root = null, end = null;

  public:
  this()
  {

  }

  ~this()
  {
   Node cursor = root;
   Node tmp;
   while (cursor != null)
   {
    tmp = cursor.next;
    delete cursor;
    cursor = tmp;
   }
  }

  void Append(T value)
  {
	Node cursor = new Node(value, end, null);
	if (!root)root = cursor;
	if (end) end.next = cursor;
	end = cursor;
  }

  void Prepend(T value)
  {
	Node cursor = new Node(value, null, root);
	if (root)root.prev = cursor;
	if (!end) end = cursor;
	root = cursor;
  }

  void InsertAfter(List_Iterator iter, T value)
  {
  	Node cursor = iter.iter_node;

  }

  void InsertBefore(List_Iterator iter, T value)
  {

  }

  List_Iterator GetFirst() {return new List_Iterator(root);}
  List_Iterator GetLast()  {return new List_Iterator(end);}

class List_Iterator
{
  private:
  Node iter_node = null;
  public:
  this(Node init){iter_node = init;}
  ~this(){}
  T Value()
  {
  	if (!iter_node) throw new IteratorNoNode("No list node connected!");
  	return iter_node.data;
  }
  void Value(T val)
  {
  	if (!iter_node) throw new IteratorNoNode("No list node connected!");
   	iter_node.data = val;
  }

}

}
}

instance TContainer(int) Container;

int main(char[] argv)
{
	printf("Init ");
	Container.List list = new Container.List();
	printf("done\n");
	printf("Append ");
	list.Append(5);
	list.Append(6);
	list.Append(7);
	list.Append(8);
	printf("done\n");
	printf("Prepend ");
	list.Prepend(4);
	list.Prepend(3);
	list.Prepend(2);
	list.Prepend(1);
	printf("done\n");
	return 0;
}
Jun 12 2003