我正在使用前向声明,现在我收到一个错误,指的是使用前向声明的类......所以 fInstance 前向声明 fConfig,然后是 Helper 类(命名空间 - 用于对函数的全局访问) - 得到 t
fConfig.h
#ifndef FCONFIG_H
#define FCONFIG_H
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <cstring>
#include <sys/types.h>
#include <fcntl.h>
#include "JWDSFork.h"
//#include "fInstance.h"
using namespace std;
class fConfig
{
private:
pid_t pid, w;
public:
pid_t cPid;
string name;
int group;
int instanceId;
int numInstance;
int tries;
bool reply;
bool debug;
bool service;
bool currentlyRunning;
time_t startTime;
time_t endTime;
string path;
fConfig();
virtual ~fConfig();
void start();
string intToString(int);
char* stringToChar(string);
};
#endif // FCONFIG_H
fInstance.h
#ifndef FINSTANCE_H
#define FINSTANCE_H
//#include "fConfig.h"
#include <vector>
#include <sys/types.h>
#include <string>
using namespace std;
class fConfig;
class fInstance
{
public:
fConfig* config;
pid_t pid;
vector<string> notes;
vector<time_t> times;
fInstance();
virtual ~fInstance();
};
#endif // FINSTANCE_H
助手.h
#ifndef HELPER_H
#define HELPER_H
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <sstream>
#include <limits.h>
#include "fInstance.h"
using namespace std;
namespace Helper
{
extern string APPDIR;
bool errorCheck(int, char*);
string charToString(char*, int);
string longToString(unsigned long);
bool Contains(vector<fInstance>, fInstance);
string convertInt(int);
string convertDouble(double);
bool Read(int, char*, size_t);
bool Write(int, char*, size_t);
};
#endif // HELPER_H
助手.cpp
//Helper.cpp - function that causes a problem
#include "Helper.h"
namespace Helper
{
bool Contains(vector<fInstance> a, fInstance b)
{
for(unsigned int i= 0; i < a.size(); i++ )
{
if(a[i].config.name == b.config.name)
{
return true;
}
}
return false;
}
}
我收到这些错误
error: request for member ‘name’ in ‘a.std::vector<_Tp, _Alloc>::operator[] [with _Tp = fInstance, _Alloc = std::allocator<fInstance>](((long unsigned int)i))->fInstance::config’, which is of non-class type ‘fConfig*’