Problem declaring nested object in another class

Hi,
I have this GameClass with 3 nested objects, and one object pointer. When I try to compile and access the BoardA object from main, I get an error message saying that 'class GameClass' has no member named 'BoardA'.

What am I doing wrong? The object pointer seems to work ok.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class GameClass{
    int BoardSz,ShipNo;

    public:
    RulesClass* Rules;

    GameClass(RulesClass* pointer){
        Rules=pointer;
        BoardSz = Rules->getGridSZ();
        ShipNo = Rules->getShipNumber();

        BoardClass BoardA(BoardSz), BoardB(BoardSz);
        FleetClass Fleet(BoardSz,ShipNo);
    }
}

int main()
{
    RulesClass Rules;
    GameSettings(&Rules);
    GameClass GameA(&Rules);

    GameA->BoardA->PrintBoard();
}
Last edited on
BoardA and Fleet are not members of the GameClass object. They are declared in the constructor which means they are not available outside the GameClass constructor is finished.

You have to declare and initialize them the same way you have done for Rules
Last edited on
Thank's smac =) Of course.. haha. I put it like that because I need to get the values as input for the Board and Fleet constructors. But I guess I have to find another way, and predefine the objects or something. I appreciate the help =)
Topic archived. No new replies allowed.