ошибка: недопустимое использование нестатического c члена данных Application :: ApplicationConstructor - PullRequest
0 голосов
/ 26 мая 2020

У меня есть это:

#ifndef APPLICATION_H
#define APPLICATION_H
#include "UserOpinion.h"
#include "ApplicationConstructor.h"
#include <vector>

using namespace std;

class Application{  
public:
  Application(char *, string, string, ApplicationConstructor &, float); //Application's Constructor
  Application(const Application &); //Copy Constructor
  virtual void ShowData() const = 0; //Virtual ShowData() Method)
  virtual ~Application(); //Destructor  
  bool operator== (const Application &) const; //Overload the == operator, this case overloads and the case of != operator
  vector<ApplicationConstructor> getApplicationConstructorVector(); //Get the Application Constructor Vector
  vector<UserOpinion> getUserOpinionVector(); //Get the User Opinion Vector       
  void setApplicationConstructorVector(vector<ApplicationConstructor> &); //Set the Application Constructor Vector
  void setUserOpinionVector(vector<UserOpinion> &); //Set the User Opinion Vector

protected:
   char *ApplicationCode;
   string ApplicationName;
   string ApplicationVersion; 
   float Price;
   ApplicationConstructor &ApplicationConstructor;
   UserOpinion *UserView;
   vector<ApplicationConstructor> &ApplicationConstructorVector; // Vector with Application Constructor Objects
   vector<UserOpinion> &UserOpinionVector; // Vector pointer to User Opinion Objects
};

#endif /* APPLICATION_H */

И это:

#ifndef APPLICATIONCONSTRUCTOR_H
#define APPLICATIONCONSTRUCTOR_H
#include <iostream>
#include <string>
#include <string.h>

using namespace std;

class ApplicationConstructor{       
private:
    string ConstructorCode;  //Constructor's code
    char  *ConstructorName;  //Constructor's name
    string ConstructorEmail; //Constructor's email
public:
    ApplicationConstructor(string, char *, string);  //Constructor
    ApplicationConstructor(const ApplicationConstructor&);  //Copy constructor
    void setConstructorCode(string);  //Set the constructor's code
    void setConstructorName(char *);  //Set the constructor's name
    void setConstructorEmail(string);  //Set the constructor's email
    string getConstructorCode();  //Get the constructor's code
    string getConstructorEmail();  //Get the constructor's email
    char *getConstructorName();  //Get the constructor's name
    bool operator== (const ApplicationConstructor &) const; //Overloading the == operator for the ApplicationConstructor class
    bool operator= (const ApplicationConstructor &); //Overloading the = operator for the ApplicationConstructor class
    void showData(); //Show the Application Constructor Data Method
    virtual ~ApplicationConstructor();  //Destructor 
};

#endif /* APPLICATIONCONSTRUCTOR_H */

И я получаю следующее:

In file included from Application.cpp:8:0:
Application.h:55:15: error: invalid use of non-static data member 'Application::ApplicationConstructor'
        vector<ApplicationConstructor> &ApplicationConstructorVector; // Vector with Application Constructor Objects
               ^~~~~~~~~~~~~~~~~~~~~~
Application.h:53:32: note: declared here
        ApplicationConstructor &ApplicationConstructor;
                                ^~~~~~~~~~~~~~~~~~~~~~
Application.h:55:15: error: invalid use of non-static data member 'Application::ApplicationConstructor'
        vector<ApplicationConstructor> &ApplicationConstructorVector; // Vector with Application Constructor Objects
               ^~~~~~~~~~~~~~~~~~~~~~
Application.h:53:32: note: declared here
        ApplicationConstructor &ApplicationConstructor;
                                ^~~~~~~~~~~~~~~~~~~~~~
Application.h:55:15: error: invalid use of non-static data member 'Application::ApplicationConstructor'
        vector<ApplicationConstructor> &ApplicationConstructorVector; // Vector with Application Constructor Objects
               ^~~~~~~~~~~~~~~~~~~~~~
Application.h:53:32: note: declared here
        ApplicationConstructor &ApplicationConstructor;
//Constructor
Application::Application(char *applicationCode, string applicationName, 
                     string applicationVersion, ApplicationConstructor &appConstructor ,
                     float price ):
                     ApplicationConstructor(appConstructor),
                     ApplicationConstructorVector(*(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;
if (!(this->FindApplicationConstructorOnVector(ApplicationConstructor))){
    this->AddToApplicationConstructorVector(this->ApplicationConstructor);
}
}

Есть предложения? Программа была запущена нормально .. Я думаю, что что-то происходит со значением const, оно помечает красным первые строки Application.h и vector .. Пожалуйста, какие-нибудь предложения? В файле Cpp есть только конструктор, в котором он работал нормально, но я не знаю, что произошло ...

Ответы [ 2 ]

0 голосов
/ 26 мая 2020
ApplicationConstructor &ApplicationConstructor;

НЕ называйте переменные и функции одинаковыми именами с типами. Это запутает компилятор.

0 голосов
/ 26 мая 2020

Трудно сказать, не увидев cpp. Однако эта строка является подозрительной:

vector<ApplicationConstructor> &ApplicationConstructorVector; 

& делает ее ссылкой, что означает, что она должна быть ссылкой на что-то и не может быть инициализирована по умолчанию. Если это не решит вашу проблему, возможно, поделитесь своим кодом.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...