Need some assistance

I am a first year C++ student who doesn't really understand the class and I need some help with a Fox and Hounds Program for my class.
Codes in Question
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Line 108   for (int i=0; i<8; ++i)
		for(int j=0; j<8; ++j)
			{
			vr.push_back(new Rectangle(Point(i*50,j*50),50,50));
				if((j+i)%2)
					vr[vr.size()-1].set_fill_color(Color::white);
		    attach(vr[vr.size()-1]);
		    }

Line 240     Vector_ref<Rectangle>vr;
	Image fox, tu1, tu2, tu3, tu4;
	Button next_button; Button next_button2; Button next_button3; Button next_button4;
	Button highscore_button; Button instruction_button; Button begin_button1; Button begin_button2;
	Button begin_button3; Button begin_button4; //Button quit_button;

Errors:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
1
1>  Project3_main.cpp
1>c:\...\project\gameWindow.h(7): error C2059: syntax error : ';'
1>c:\...\project\gameWindow.h(240): error C2872: 'Rectangle' : ambiguous symbol
1>          could be 'C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\wingdi.h(3989) : BOOL Rectangle(HDC,int,int,int,int)'
1>          or       'c:\...\project\Graph.h(193) : Graph_lib::Rectangle'
1>c:\...\project\gameWindow.h(240): error C2872: 'Rectangle' : ambiguous symbol
1>          could be 'C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\wingdi.h(3989) : BOOL Rectangle(HDC,int,int,int,int)'
1>          or       'c:\...\project\Graph.h(193) : Graph_lib::Rectangle'
1>c:\...\project\gameWindow.h(240): error C2923: 'Graph_lib::Vector_ref' : 'Rectangle' is not a valid template type argument for parameter 'T'
1>          C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\wingdi.h(3989) : see declaration of 'Rectangle'
1>c:\...\project\gameWindow.h(102): error C2512: 'Graph_lib::Vector_ref' : no appropriate default constructor available
1>c:\...\project\gameWindow.h(111): error C2872: 'Rectangle' : ambiguous symbol
1>          could be 'C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\wingdi.h(3989) : BOOL Rectangle(HDC,int,int,int,int)'
1>          or       'c:\...\project\Graph.h(193) : Graph_lib::Rectangle'
1>c:\...\project\gameWindow.h(111): error C2061: syntax error : identifier 'Rectangle'
1>c:\...\project\gameWindow.h(111): error C2661: 'Graph_lib::Vector_ref<T>::push_back' : no overloaded function takes 2 arguments
1>c:\...\project\gameWindow.h(111): error C2143: syntax error : missing ';' before ')'
1>c:\...\project\gameWindow.h(111): error C2143: syntax error : missing ';' before ')'
1>c:\...\project\gameWindow.h(113): error C2662: 'Graph_lib::Vector_ref<T>::size' : cannot convert 'this' pointer from 'Graph_lib::Vector_ref' to 'const Graph_lib::Vector_ref<T> &'
1>          Reason: cannot convert from 'Graph_lib::Vector_ref' to 'const Graph_lib::Vector_ref<T>'
1>          Conversion requires a second user-defined-conversion operator or constructor
1>c:\...\project\gameWindow.h(113): error C2228: left of '.set_fill_color' must have class/struct/union
1>c:\...\project\gameWindow.h(116): error C2662: 'Graph_lib::Vector_ref<T>::size' : cannot convert 'this' pointer from 'Graph_lib::Vector_ref' to 'const Graph_lib::Vector_ref<T> &'
1>          Reason: cannot convert from 'Graph_lib::Vector_ref' to 'const Graph_lib::Vector_ref<T>'
1>          Conversion requires a second user-defined-conversion operator or constructor
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I can't figure out what the errors want me to do to change the code.
Thanks for any help that you can give.
closed account (D80DSL3A)
It looks like there are conflicting definitions for a Rectangle object.

Compiler can't figure out if you mean one of these:
could be...BOOL Rectangle(HDC,int,int,int,int)
or one of these:
or 'c:\...\project\Graph.h(193) : Graph_lib::Rectangle'

Is there a Rectangle defined in Graph.h? Are you using namespace Graph_lib somewhere (commingling namespaces)?
Rectangle is defined in Graph.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
struct Rectangle : Shape {

    Rectangle(Point xy, int ww, int hh) : w(ww), h(hh)
    {
        add(xy);
        if (h<=0 || w<=0) error("Bad rectangle: non-positive side");
    }

    Rectangle(Point x, Point y) : w(y.x-x.x), h(y.y-x.y)
    {
        add(x);
        if (h<=0 || w<=0) error("Bad rectangle: non-positive width or height");
    }
    void draw_lines() const;

    int height() const { return h; }
    int width() const { return w; }
private:
    int h;    // height
    int w;    // width
};

and this is in Graph.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
void Rectangle::draw_lines() const
{
    if (fill_color().visibility()) {    // fill
        fl_color(fill_color().as_int());
        fl_rectf(point(0).x,point(0).y,w,h);
        fl_color(color().as_int());    // reset color
    }

    if (color().visibility()) {    // lines on top of fill
        fl_color(color().as_int());
        fl_rect(point(0).x,point(0).y,w,h);
    }
}

I have namespace Graph_lib in one of the parts, but taking it off just results in even more problems.
closed account (D80DSL3A)
So, which Rectangle object did you intend to be referring to on the lines in question?

If it's supposed to be a Graph_lib::Rectangle then try qualifying it as such where you are using it.

eg: Line 240 Vector_ref<Graph_lib::Rectangle>vr;

If it's the other , then I don't know.
Last edited on
That fixed most of the errors and I'm going to work on the others. Thanks for all the help!
Topic archived. No new replies allowed.