错误: 无效使用非静态数据成员"应用程序::应用程序构造函数"
error: invalid use of non-static data member 'Application::ApplicationConstructor'
>我有这个:
#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 的第一行和 at 向量标记为红色。请提出任何建议?Cpp 文件只有运行良好的构造函数,但我不知道发生了什么......
没有看到 cpp 很难分辨。不过,这一行是可疑的:
vector<ApplicationConstructor> &ApplicationConstructorVector;
&使它成为引用,这意味着它需要是对某些内容的引用,并且不能默认初始化。如果这不能解决您的问题,可以分享更多代码。
ApplicationConstructor &ApplicationConstructor;
不要将变量和函数命名为与类型相同的名称。这会混淆编译器。
相关文章:
- PC中的程序和PHONE中的本机描述应用程序之间的数据连接
- 如何在不破坏现有应用程序的情况下更改 API 中 stl 容器的数据类型?
- 在 1 个服务器 n 客户端套接字 C++ MFC 应用程序中更新数据的客户端
- 错误: 无效使用非静态数据成员"应用程序::应用程序构造函数"
- 更改应用程序数据的路径
- 使用 pipe() 和 fdopen() 将数据从 Python 脚本传递到 Windows 中的C++应用程序
- 用于向公众公开数据成员的帮助程序结构
- 将数据从一个应用程序单向发送到另一个应用程序的最佳做法
- 从 Windows 中的其他应用程序 GUI 中提取数据
- 无法使用管道将数据发送到我通过exec(C++)启动的第二个应用程序
- 在网格视图中显示数据 - 基于 MFC c++ 对话框的应用程序
- 安卓中的Qt和应用程序数据存储
- 从Qt应用程序读取元数据
- [[MASE_UNUSE]]应用于静态数据成员
- 是否有一种简单的方法可以从普通的 win32 C++代码向应用程序见解提供数据?
- 关系应用程序数据的并发更新
- Qt指定某些应用程序数据的位置
- C++编程:导航到用户文件以保存每个用户的应用程序数据
- 如何使用Visual C++应用程序的完整应用程序数据读取Minidump的应用程序数据
- 如何使用C++在RAD Studio XE6中存储Android应用程序数据/设置