I have classes Shape and Document.
Document holds Shapes.
Document has a list<Shape*> _shapes.
But I would like to have a pointer to Document in Shape, too.
And I would like to call some Document methods from Shape.
Here is short version of code:
document.h
1 2 3 4 5 6
include "shape.h"class Document
{
list<Shape*> _shapes;
//...
}
shape.h
1 2 3 4 5 6
class Document;class Shape
{
document* _pointerToMyDocument;
//...
}
Now when I call _pointerToMyDocument->SetSomething();
compilation fail with error:
1 2
invalid use of undefined type `struct Document'
forward declaration of `struct Document'
classDocument;
class Shape
{
document* _pointerToMyDocument;
//...
}
Now when I call _pointerToMyDocument->SetSomething();
compilation fail with error:
invalid use of undefined type `struct Document'
forward declaration of `struct Document'
I think that the code where you are using the call _pointerToMyDocument->SetSomething(); does not see yet the definition of class Document. Maybe you should place the code where you are using this call after the definition of class Document.