samedi 30 septembre 2017

C++ Private Inner Class

I have a question about privately defined inner class

#pragma once
#ifndef CIRCULAR_ARRAY_H
#define CIRCULAR_ARRAY_H

class CircularArray
{
private:
   class Node
   {
   private:
      int data;
      Node* next;
   public:
      Node(int val, Node* next) : data(val), next(next) {}
      ~Node() { delete[] next; }
      int get_data(void);
   };

   Node* head;

public:

   Node* add(int data, Node* next);
};

Node* CircularArray::add(int data, Node* next)
{

}

#endif

Why am I unable to access Node in the method definition CircularArray::add? I thought that a private inner class Node would be accessible to CircularArray because private members of a class are visible to the class the same way they are visible to a derived class? Is there an exception when that private member is a class?

Does c++ not support private inner classes like Java? Do I have to publicize inner classes for their members to be accessible?

Aucun commentaire:

Enregistrer un commentaire