0

I have these files:

pi_utilities.h

    #ifndef UTILITIES_H_
#define UTILITIES_H_

#include <set>
#include <vector>

typedef unsigned short int MYTYPE2;

namespace pi
{
   class dfa;
}

using namespace std;

struct ir_statistical_measures
{
    // True positive, and so on.
    int tp = 0;
    int tn = 0;
    int fp = 0;
    int fn = 0;

    int dim_positive=0; 
    int dim_negative=0; 

    double accuracy  = 0; //(number in [0 1])
    double precision = 0;
    double recall = 0;
    double f_measure = 0;
    double matthews = 0;
    double specificity = 0; //this is recall- or true negative rate
    double bcr = 0;
};


void compute_ir_stats(const pi::dfa* dfa1 ,const pi::dfa* target,const set<vector<MYTYPE2>> &test_set,ir_statistical_measures &stats);
#endif

pi_utilities.cpp

 #include "pi_utilities.h"

void compute_ir_stats(const pi::dfa* dfa1 ,const pi::dfa* target,const set<vector<MYTYPE2>> &test_set,ir_statistical_measures &stats)
{
   bool result;
   result = dfa1->mq(true);
   result = target->mq(false);
}

pi_dfa.h

    #ifndef DFA_H_
#define DFA_H_

#include <string>
#include <vector>
#include <set>

#include "pi_utilities.h"

typedef unsigned short int MYTYPE;

using namespace std;

extern struct ir_statistical_measures &stats; //I say to compiler that definition isn't here

namespace pi
{
   class dfa
   {
        public:
        bool compare_dfa(const dfa *dfa_to_compare,string method,ir_statistical_measures &stats1,ir_statistical_measures &stats2) const;

        bool m_q(bool flag) const;

    };
}
#endif

pi_dfa.cpp

#include "pi_dfa.h"



bool pi::dfa::compare_dfa(const dfa *dfa_to_compare , string method , ir_statistical_measures &stats1 , ir_statistical_measures &stats2) const
{
   set<vector<MYTYPE>> test_set;
   compute_ir_stats(dfa_to_compare,this,test_set,stats1); 

   return true;
}

bool pi::dfa::m_q(bool flag) const
{
   return flag;
}

main.cpp

#include "pi_dfa.h"
#include "pi_utilities.h"

int main()
{
   pi::dfa* L_dfa=NULL;  
   L_dfa = new pi::dfa();
   pi::dfa* O_dfa=new pi::dfa();

   bool value_return;
   struct ir_statistical_measures test_set_ir_statistical_measures; //struct defined in pi_utilities.h
   struct ir_statistical_measures test_set_ir_statistical_measures2;
   value_return = L_dfa->compare_dfa(O_dfa,"method",test_set_ir_statistical_measures,test_set_ir_statistical_measures2);
}

There is a circular dependency problem. To resolve I used forward declaration, but with the pointer of the class dfa I have to call a function of the class too, thus the definition there isn't and the compiler goes into trouble, I get these compile errors:

    pi_utilities.cpp: In function ‘void compute_ir_stats(const pi::dfa*, const pi::dfa*, const std::set<std::vector<short unsigned int> >&, ir_statistical_measures&)’:
pi_utilities.cpp:6:17: error: invalid use of incomplete type ‘const class pi::dfa’
    result = dfa1->mq(true);
                 ^
In file included from pi_utilities.cpp:1:0:
pi_utilities.h:11:10: error: forward declaration of ‘const class pi::dfa’
    class dfa;
          ^
pi_utilities.cpp:7:19: error: invalid use of incomplete type ‘const class pi::dfa’
    result = target->mq(false);
                   ^
In file included from pi_utilities.cpp:1:0:
pi_utilities.h:11:10: error: forward declaration of ‘const class pi::dfa’
    class dfa;

Thus forward declaration isn't enough.
How could I fix it?

I'm using C++11 (The code here is rearranged to a minimal executable version)

Nick
  • 1,439
  • 2
  • 15
  • 28

0 Answers0