Ciao a tutti
Stavo cercando di creare un associazione uno ad uno bidirezionale, associo a Persona un Gatto tramite la funzione adotta(), tale funzione associa anche alla Classe Gatto una Persona.
Se non che mi da il seguente errore
 In file included from pad.h:4:0,
                 from main.cpp:3:
gatto.h: In member function ‘void Gatto::stampaPad() const’:
gatto.h:19:39: error: invalid use of incomplete type ‘class Persona’
             if(mypad!=NULL)cout<<mypad->getNome();
                                       ^~
gatto.h:6:7: note: forward declaration of ‘class Persona’
 class Persona;
Ho provato a togliere gli #include e mettere direttamente class Nome_classe; negli header ma continua a darmi errore, qualcuna sa cosa posso fare? questo è il codice:
File pad.h
#ifndef P_H
#define P_H
#include <cstring>
#include "gatto.h"
class Gatto;
using namespace std;
class Persona{
    private:
         string nome;
         Gatto *mycat;
    public:
         Persona(string n=" "):nome(n){mycat=NULL;}
         
         void adotta(Gatto &g){
             mycat=&g;
             mycat->addPad(*this);
         }
         
         string getNome() const{return nome;}
         
         void nomeCat(){
             if(mycat!=NULL)cout<<mycat->getNome();
             else cout<<"non ho gatti";
         }
         
         void abbandona(){mycat=NULL;}
};
#endif
File gattp.h
#ifndef C_H
#define C_H
#include <cstring>
#include "pad.h"
using namespace std;
class Persona;
class Gatto{
    private:
        string nome;
        Persona *mypad;
    public:
        Gatto(string n=" "):nome(n){mypad=NULL;}
        
        void addPad(Persona &p){mypad=&p;}
        
        string getNome() const{return nome;}
        
        void stampaPad() const{
            if(mypad!=NULL)cout<<mypad->getNome();
        }
};
#endif
File main
#include <iostream>
#include "pad.h"
#include "gatto.h"
using namespace std;
int main(){
    Persona p("Carlo");
    Gatto g("Fuffi");
    
    p.adotta(g);
    p.nomeCat();
    
    p.abbandona();
    p.nomeCat();
    g.stampaPad();
    return 0;
}