Reference in class, defined when created?

I'm having abit of a problem having a reference to a parent classes data member, the trouble is passing the variable in the class definition. I'm really unsure how to do this.

Class header code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class eMap
{
public:
   unsigned short width;

   class Tiles
   {
   public:
      Tiles_T grid;

      unsigned short& width;
      unsigned char depths;
      unsigned int count;

      Tiles(unsigned short&);
   } tiles(width);  //Problem lies here
};


Definition:
1
2
3
4
eMap::Tiles::Tiles(unsigned short& width): width(width)
{

}


So I am basically trying to pass a data member as a reference to an instantiated object.

Any help is appreciated,
Thanks.
Why would Tile need to know it's width if it is a property of the map and not the Tile? You could try using a pointer instead if you need it:

unsigned short* const width;
Well this was a section rather than the entire code, so it does look stupid, just the idea is in there.

Managed to get it.
Topic archived. No new replies allowed.