C++ 如何实例化将生成并返回另一个类的对象的类的对象?

C++ 如何实例化将生成并返回另一个类的对象的类的对象?,c++,queue,instantiation,C++,Queue,Instantiation,这才是真正的问题。实例化给定类的对象:AirPlaneGenerator,它将在间隔时间(在实例化期间设置)结束时生成并返回飞机对象。注意:生成器将在间隔之间返回NULL;表示目前没有飞机着陆。 这是机场生成器文件的cpp文件 #include "airplanegenerator.h" // initialize the static list of tasks vector<AirPlane> AirPlaneGenerator::lstPlane

这才是真正的问题。实例化给定类的对象:AirPlaneGenerator,它将在间隔时间(在实例化期间设置)结束时生成并返回飞机对象。注意:生成器将在间隔之间返回NULL;表示目前没有飞机着陆。 这是机场生成器文件的cpp文件

    #include "airplanegenerator.h"
        // initialize the static list of tasks
    vector<AirPlane> AirPlaneGenerator::lstPlanes(0);
    // -- Constructors --
     // default constructor
    AirPlaneGenerator::AirPlaneGenerator(int i) {
// initialise all airplanes within the list
this->interval = i;
this->cursor = 0;
this->elapsed = 0;

     AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new      

      AirPlane(JFF_GOVERNMENT));

      AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new    
    AirPlane(JFF_MAIL));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new  
    AirPlane(JFF_VIP));

    AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new  
     AirPlane(JFF_MAIL));
 AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new   
     AirPlane(JFF_MAIL));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new   
     AirPlane(JFF_GOVERNMENT));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new   
     AirPlane(JFF_VIP));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new   
     AirPlane(JFF_VIP));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new 
     AirPlane(JFF_MAIL));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new   
     AirPlane(JFF_SMALLPASS));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new  
    AirPlane(JFF_SMALLPASS));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new 
    AirPlane(JFF_SMALLPASS));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new  
    AirPlane(JFF_VIP));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new 
    AirPlane(JFF_LARGEPASS));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new 
    AirPlane(JFF_MAIL));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new 
     AirPlane(JFF_LARGEPASS));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new    
    AirPlane(JFF_SMALLPASS));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new 
    AirPlane(JFF_GOVERNMENT));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new 
     AirPlane(JFF_MAIL));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new 
     AirPlane(JFF_LARGEPASS));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new 
     AirPlane(JFF_GOVERNMENT));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new 
     AirPlane(JFF_GOVERNMENT));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new 
    AirPlane(JFF_LARGEPASS));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new 
    AirPlane(JFF_SMALLPASS));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new     
    AirPlane(JFF_MAIL));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new 
    AirPlane(JFF_MAIL));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new 
    AirPlane(JFF_MAIL));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new 
    AirPlane(JFF_SMALLPASS));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new 
    AirPlane(JFF_VIP));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new 
    AirPlane(JFF_GOVERNMENT));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new 
    AirPlane(JFF_LARGEPASS));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new 
    AirPlane(JFF_GOVERNMENT));
cout << " GENERATOR: AirPlanes Are Ready For Landing." << endl;
}
// -- Other Interfaces --
// get the next task in the list
AirPlane* AirPlaneGenerator::getNext() {
     // find out the current elapsed time
    this->elapsed += 1;
    // return an airplane if the elapsed time exceeds the current cursor position
     if (this->elapsed / this->interval >= 1) {
    this->elapsed -= this->interval;
    if (this->cursor < TOTALPLANES) {
        cout << " GENERATOR: AirPlane# " <<   
AirPlaneGenerator::lstPlanes[this->cursor].getIdnum() << " Now Landing." << endl;
        return &(AirPlaneGenerator::lstPlanes[this->cursor++]);
    } else {
        cout << " GENERATOR: No More AirPlanes In The Air To Land." << endl;
        return NULL;
    }
    } else {
    cout << " GENERATOR: No AirPlane Landing Now." << endl;
    return NULL;
   }
}
#包括“airplanegenerator.h”
//初始化任务的静态列表
向量飞机生成器::lstPlanes(0);
//--建设者--
//默认构造函数
AirPlaneGenerator::AirPlaneGenerator(int i){
//初始化列表中的所有飞机
这个->间隔=i;
该->光标=0;
这个->经过=0;
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(),新建
飞机(JFF_政府);
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(),新建
飞机(JFF_邮件);
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(),新建
飞机(JFF_VIP);
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(),新建
飞机(JFF_邮件);
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(),新建
飞机(JFF_邮件);
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(),新建
飞机(JFF_政府);
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(),新建
飞机(JFF_VIP);
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(),新建
飞机(JFF_VIP);
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(),新建
飞机(JFF_邮件);
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(),新建
飞机(JFF_SMALLPASS);
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(),新建
飞机(JFF_SMALLPASS);
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(),新建
飞机(JFF_SMALLPASS);
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(),新建
飞机(JFF_VIP);
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(),新建
飞机(JFF_LARGEPASS);
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(),新建
飞机(JFF_邮件);
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(),新建
飞机(JFF_LARGEPASS);
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(),新建
飞机(JFF_SMALLPASS);
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(),新建
飞机(JFF_政府);
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(),新建
飞机(JFF_邮件);
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(),新建
飞机(JFF_LARGEPASS);
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(),新建
飞机(JFF_政府);
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(),新建
飞机(JFF_政府);
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(),新建
飞机(JFF_LARGEPASS);
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(),新建
飞机(JFF_SMALLPASS);
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(),新建
飞机(JFF_邮件);
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(),新建
飞机(JFF_邮件);
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(),新建
飞机(JFF_邮件);
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(),新建
飞机(JFF_SMALLPASS);
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(),新建
飞机(JFF_VIP);
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(),新建
飞机(JFF_政府);
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(),新建
飞机(JFF_LARGEPASS);
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(),新建
飞机(JFF_政府);
无法通过/此->间隔>=1){
此->经过-=此->间隔;
如果(此->光标问题是您需要实现Creational Pattern(),它将在给定的间隔时间后创建类的对象。

我知道如何创建对象,但我不明白问题要我做什么感谢您的响应。首先,我听说了这个工厂模式。将有一个readThat即设计模式,这非常简单(最容易)理解。发布的类是要处理的给定类。我认为我不应该篡改它,即设计。这种设计方法应该在main中实现?