在构造函数C中实例化一个指向对象向量的指针

我有以下几点:

class Application{  
protected:
   //Many getters , setters, and other methods
   Application(char *, string, string, ApplicationConstructor &, float); //Application's Constructor     
   ApplicationConstructor &AppConstructor;
   UserOpinion *UserView;
   vector<ApplicationConstructor> &AppConstructorVector; // Vector with Application Constructor Objects
   vector<UserOpinion> *UserOpinionVector; // Vector pointer to User Opinion Objects
};

和这个构造函数:

//Constructor
Application::Application(char *applicationCode, string applicationName, 
                     string applicationVersion, ApplicationConstructor &appConstructor ,
                     float price ):
                     AppConstructor(appConstructor),
                     AppConstructorVector(*(new vector<ApplicationConstructor>())),
                     UserOpinionVector(new vector<UserOpinion>()){
    int i = strlen(applicationCode);
    ApplicationCode = new char[i+1];
    strncpy(ApplicationCode, applicationCode, (i+1));
    ApplicationName = applicationName;
    ApplicationVersion = applicationVersion;
    Price = price;
    UserView = nullptr;
 // UserOpinionVector = nullptr;
 // if (!(this->FindAppConstructorOnVector(this->AppConstructor))){
 //     this->AddToAppConstructorVector(this->AppConstructor);
 // }
}

如果我删除对UserOpinionVector = nullptr的评论;它运行平稳,但是在构造函数上声明时,出现运行时错误。当应用程序对象无效时,如何像新的代码一样使新的UserOpinionVector无效? AppConstructorVector(*(newvector()))无效,请不要说我改变UserOpinionVector声明为属性的方式,我有这个要求要完成。 提前致谢!!!

评论