开发者

Defining a constructor of a private class

Queue and airportSim classes are defined.

class Queue
{
    public:
       Queue(int setSizeQueue = 20);

    //Queue's contents
}

class airportSim
{
    public:
       airportSim(int setSizeRunway = 20);

    private:
       Queue airQueue;
       Queue groundQueue;

    //Other airportSim contents.
}

Queue::Queue(int setSizeQueue)
{
   //Contents of airportSim constructor sup开发者_高级运维posed to come here.
}

airportSim::airportSim(int setSizeRunway)
{
    airQueue(setSizeRunway);
    groundQueue(setSizeRunway);
}

It says it has trouble accessing the constructors. Anyone know how to define the constructor of the queues?


Use the initialization list syntax:

airportSim::airportSim(int setSizeRunway)
    : airQueue(setSizeRunway),
      groundQueue(setSizeRunway)
{
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜