Enum types and classes

I can't seem to understand how to fill an array made in class A with an enumerator type made in class B and these two classes are separate files.
I know some stuff is missing but its just a rough example.


example...

1
2
3
4
5
6
7
8
9
10
11
12
//class A

#using namespace std;
  class A
{
   private:
   int array[5][5];
   
   public:
   void setArray(int array[][5];
      
}


1
2
3
4
5
6
7
8
9
 // clas A.cpp
 #include "A.h"
 #include "B.h"
 
 void A :: setArray(int array[][5])
{
   array[0][0]=Blue;
   array[0][1]=Red;
}





1
2
3
4
5
6
// class B
class B
{
private:
        enum color{Blue,Red,Green,Orange} colors;
]
1
2
3
4
5
6
7
8
9
10
11
class B
{
    public: enum colour_t { Blue, Red, Green, Orange };
};

class A
{
    int numbers[4] = { B::Blue, B::Red, B::Green, B::Orange } ;

    B::colour_t colours[4] = { B::Blue, B::Red, B::Green, B::Orange } ;
};
The thing is the Enum has to be private
Why does it have to be private?
requirement.
Good:
1
2
3
4
5
6
7
8
9
10
11
12
13
class B
{
    public: enum colour_t { Blue, Red, Green, Orange }; // type is public

    private: colour_t the_colour = Green ; // member object is private
};

class A // define class A
{
    int numbers[4] = { B::Blue, B::Red, B::Green, B::Orange } ;

    B::colour_t colours[4] = { B::Blue, B::Red, B::Green, B::Orange } ;
};


Not so good:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class A ; // declare class A

class B // define class B
{
    private: enum colour_t { Blue, Red, Green, Orange };

    friend A ; // *** not a great idea if this is 'long-distance' (cross-component) friendship
};

class A // define class A
{
    int numbers[4] = { B::Blue, B::Red, B::Green, B::Orange } ;

    B::colour_t colours[4] = { B::Blue, B::Red, B::Green, B::Orange } ;
};
Topic archived. No new replies allowed.