Pergunta

Im not sure why I am getting this error..."error: field 'config' has incomplete type". I have tried to do forward declaration and including the headers using #include...Im just trying to include fConfig in fInstance...

#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:
    pid_t pid;
    fConfig config;
    vector<string> notes;
    vector<time_t> times;

    fInstance();
    virtual ~fInstance();
};

#endif // FINSTANCE_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

EDIT: Added changes

#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:
    pid_t pid;
    fConfig* config;
    vector<string> notes;
    vector<time_t> times;

    fInstance();
    virtual ~fInstance();
};

#endif // FINSTANCE_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
Foi útil?

Solução

You need to add #include "fConfig.h" in fInstance.h and you don't need to include fInstance.h in fConfig.h because it appears that you are not using the type fInstance in fConfig.h.

When you forward declare a type compiler doesn't know the memory layout of that type and so it treats the type as an Incomplete type & the compiler cannot do any operations for which it needs to know the memory layout of that type.

You create an instance of fConfig after forward declaring it, to do that compiler needs to know the memory layout of fConfig but since you just forward declared it, it doesn't know that and hence complains.

Outras dicas

You need to put the full definition of fConfig before that of fInstance. The forward declaration won't do because your fInstance has an fConfig data member, so the full type is necessary:

in fConfig.h:

#ifndef FCONFIG_H
#define FCONFIG_H

class fConfig {
  // as in original
};

#endif

in fInstance.h:

#ifndef FINSTANCE_H
#define FINSTANCE_H

#include "fConfig.h" // need to include to get full type

class fInstance {
  // as in original
};

#endif
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top