I have a problem with my classes.
I have two separate headers. Color.h and Painter.h:
1). Color.h
class Color{
int number;
public:
void initialize();
void change (Painter draw);
}
2). Painter.h
class Painter{
Color a,b;
public:
void get();
void draw();
}
My problem is, that i need to use Painter in class Color, and class Painter use Color. In Qt, i get a error that Painter is not a type. How can i fix this? What is solution for that problem?
In Painter.h you need to include Color.h, because you have objects of type Color.
But in color.h you can add a forward declaration for the Painter class:
class Painter;
class Color{
int number;
public:
void initialize();
void change (Painter draw); //a forward declaration is enough for this
}
And the method void change (Painter draw); you will define it in the color.cpp and there you include painter.h
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With