-1

Hello I have two classes Zonk and Orfina, and I want have an object at each of these classes. My code look as follows:

#ifndef ZONK_H
#define ZONK_H

class Zonk;

class Orfina
{
    Zonk zonkmm;
};



class Zonk
{
    Orfina orfina;
public:
    Zonk();
};

#endif // ZONK_H

When I try to compile I get an error:

C:\Qt\Tools\QtCreator\bin\test\zonk.h:8: error: field 'zonkmm' has incomplete type
 Zonk zonkmm;
      ^
TheDarkKnight
  • 27,181
  • 6
  • 55
  • 85
user3700021
  • 49
  • 2
  • 2
  • 6

1 Answers1

2

Use pointers in the declaration, and include the headers in the definitions.

//Orfina.hpp
class Zonk;
class Orfina
{
Zonk* zonkmm;

public:

};

//Zonk.hpp
class Orfina;
class Zonk
{
    Orfina* orfina;
public:
    Zonk();
};

// Orfina.cpp
#include "Zonk.hpp"

// Zonk.cpp
#include "Orfina.hpp"
Appleshell
  • 7,088
  • 6
  • 47
  • 96