0

Hello I want to access a nested class from other class.

class OutSideClass
{
public:
    class InSideClass
    {
       ...
    };
    friend class InSideClass;
};

class Other
{
    InSideClass x; // This doesn't work
};

The class InSideClass is a public class so I don't understand why can I access it from outside

I also want to access

template <typename T>
class OutSideClass
{
public:
    class InSideClass
    {
        class InSideClassIterator
        {

        };
    };


public:
    class Other
    {
    OutSideClass<T>::InSideClass::InSideClassIterator x;
    };


};
user75453
  • 51
  • 6

1 Answers1

6

The class InSideClass is inside OutSideClass, so you have to specify so.

class Other
{
    OutSideClass::InSideClass x; // This should work
};

In the second case, the declaration is inside OutSideClass, so you should remove OutSideClass<T>:: from the declaration.

Also typename seems to be required according to these:

MikeCAT
  • 73,922
  • 11
  • 45
  • 70
  • Can you explain what should I do when OutSideClass has template. For example `template class OutSideClass` – user75453 Sep 22 '20 at 13:17
  • 1
    @user75453 `OutSideClass::InSideClass x;`. `something` should what you want like `int`. – MikeCAT Sep 22 '20 at 13:23
  • I have edited my question can you explain how to acess that. It seems like in that case it does'nt works – user75453 Sep 22 '20 at 13:36
  • @user75453 Add template argument for `OutSideClass` like my previous reply. – MikeCAT Sep 22 '20 at 13:37
  • @user75453 The declaration is inside `OutSideClass` in this case, so `OutSideClass::` should be removed. – MikeCAT Sep 22 '20 at 13:44
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/221878/discussion-between-user75453-and-mikecat). – user75453 Sep 22 '20 at 13:47