定义私有类的构造函数

时间:2011-10-04 02:54:30

标签: constructor

定义了队列和airportSim类。

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 supposed to come here.
}

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

它说它无法访问构造函数。任何人都知道如何定义队列的构造函数?

1 个答案:

答案 0 :(得分:1)

使用initialization list语法:

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