我有这个:
#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文件只有运行良好的构造函数,但我不知道发生了什么...
答案 0 :(得分:0)
不看cpp就很难说出来。但是此行是可疑的:
vector<ApplicationConstructor> &ApplicationConstructorVector;
&使其成为引用,这意味着它需要成为 的引用,并且不能默认初始化。如果这样做不能解决您的问题,则可以共享更多代码。
答案 1 :(得分:0)
ApplicationConstructor &ApplicationConstructor;
请勿命名变量,并且函数应与类型具有相同的名称。它将使编译器感到困惑。