0

I have a problem, the Rectangle class is not working properly in TwoDimTree.h For example, "Rectangle Extent;" seems like working ,but when i try to use it it says no member class found.

I want to use it like "Extent.get_Top;" , but i cant make it.

Also in the error list i got. Error 7 error C2027: use of undefined type 'Rectangle'

My headers are below.I really couldn't find my mistake.Thanks for the help.

My TwoDimTree.h

#include <string>
#include "Rectangle.h"
#include "LinkedList.h"
using namespace std;
class TwoDimTreeNode
{
public:
    TwoDimTreeNode(Rectangle,TwoDimTreeNode*,TwoDimTreeNode*,TwoDimTreeNode*,TwoDimTreeNode*,LinkedList<Rectangle>,LinkedList<Rectangle>);
    TwoDimTreeNode(Rectangle);
    Rectangle get_Extent();
private:
    Rectangle Extent;
    LinkedList <Rectangle> Vertical;
    LinkedList <Rectangle> Horizontal;
    TwoDimTreeNode*TopLeft;
    TwoDimTreeNode*TopRight;
    TwoDimTreeNode*BottomLeft;
    TwoDimTreeNode*BottomRight;


    friend class Rectangle;
    friend class LinkedList<Rectangle>;
};

My Rectangle.h

#include <string>
#include "TwoDimTreeNode.h"
#include "LinkedList.h"

using namespace std;
class Rectangle {
public:
    Rectangle(int,int,int,int);
int get_Top();
    void set_Top(int);
private:
    int Top;
    int Bottom;
    int Right;
    int Left;

    friend class TwoDimTreeNode;
    friend class LinkedList<Rectangle>;

};

My Linkedlist.h

#include <string>
#include "Rectangle.h"
#include "TwoDimTreeNode.h"
using namespace std;

template <class Object>
struct node
{
    Object element;
    node*next;
    node(const Object & theElement = Object(),node*n=NULL)
        :element(theElement), next(n){}
    friend class Rectangle;
    friend class TwoDimTreeNode;
};
template <class Object>
class LinkedList
{
public:
    LinkedList();
    int get_Length();
    Object search(int,int);
    bool check_Rectangle(Object);
private:

    int length;
    node<Object>*head;

};
M.J.Watson
  • 470
  • 7
  • 18
  • You look to be creating a generic linked list, but you hardcode it to have rectangle-containing-properties due to `check_Rectangle` (why would a list of non-rectangles want this?) and the friend classes. In fact I would check you need so many friends. Also your `search` function returns a copy of the contained object. – Neil Kirk Nov 05 '15 at 23:35
  • I am using that programme to only find the rectangles. – M.J.Watson Nov 05 '15 at 23:49

1 Answers1

1

you have a cyclic include. Rectangle.h includes twodimtree. twodimtree includes rectangle

The net effect is that TwoDimTree is process first and that referes to Rectangle thats not defined yet

Remove include twodimtree from rectangle

pm100
  • 48,078
  • 23
  • 82
  • 145