printing a grid using a class

Hello, I'm stuck on printing my grid from my class file to the main file.
If I pull out the print code and put in on the actual main program, it prints, but if I try to put in the class methods and call the function from main, I get an error.
[quote]
Could anyone tell me what I'm doing wrong here?

testfile.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <vector>
#include <string>
#include "DUPoint.h"
#include "Grid.h"
using namespace std;

int main() {

	Grid bacon;
	bacon.output(cout);

	return 0;
}


grid.h file
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#ifndef _GRID_
#define _GRID_

#include "DUPoint.h"
#include <vector>
using namespace std;

class Grid
{

	public:
		
		Grid();
		Grid(DUPoint start, DUPoint end);
		Grid( const Grid & a );

		~Grid();
		
		DUPoint getStart(DUPoint start) const;
		DUPoint getEnd(DUPoint end) const;

		DUPoint setStart(DUPoint start);
		DUPoint setEnd(DUPoint start);

		bool isLegalMove(int startPosRow, int startPosColumn,int endPosRow,int endPosColumn);
		void applyMove(int startPosRow, int startPosColumn, int endPosRow, int endPosColumn);

		void output(ostream & out);

	private:

		DUPoint startPos_;
		DUPoint endPos_;

		vector< vector<int> > grid_ ;



};
#endif 


grid.cpp
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <iostream>
#include "Grid.h"
#include "DUPoint.h"
#include <vector>
#include <sstream>

using namespace std;
		
	Grid::Grid() { }

	Grid::Grid(DUPoint start, DUPoint end) 
	{
		startPos_ = start;
		endPos_ = end;
	}

	Grid::Grid( const Grid & a ) 
	{
		startPos_ = a.getStart ;
		endPos_ = a.getEnd ;
	}
	
	DUPoint Grid::getStart(DUPoint start) const 
	{
		return startPos_;
	}
	DUPoint Grid::getEnd(DUPoint end) const 
	{
		return endPos_;
	}

	DUPoint Grid::setStart(DUPoint start) 
	{
		startPos_ = start;
	}
		
	DUPoint Grid::setEnd(DUPoint end) 
	{
		endPos_ = end;
	}

	bool Grid::isLegalMove(int startPosRow, int startPosColumn,int endPosRow,int endPosColumn) 
	{
		
		if ( startPosRow < 0 || startPosRow > 3 
			 || startPosColumn < 0 || startPosColumn > 3
			 || endPosRow < 0 || endPosRow > 3 )
		 return false;
		else 
			return true;
		
				 
	}
		
	void Grid::applyMove(int startPosRow, int startPosColumn, int endPosRow, int endPosColumn)
	{
		if (isLegalMove) {
			startPosRow = 0;
			startPosColumn = 0;
			endPosRow = 0;
			endPosColumn = 0;
		}else 
			exit(1);
		
	}

	void Grid::output(ostream & out) {
		vector<vector<int>> grid(4);
				
		for(int i=0; i<4; i++)
		{
			vector<int> current(4);
			for(int j=0; j<4; j++)
			{
				current[j]=j % 2;
			}
			grid[i] = current;
		}

		int rows, columns;
		out << "    0 1 2 3 " << endl;
		out << "+---------+" <<  endl;
		for( rows=0; rows<grid.size(); ++rows ) // make each row
		{
		out << rows << " | ";		
			for( columns=0; columns < grid[rows].size(); ++columns ) //make each column
			{
				if( grid[rows][columns]==1)
				{
					out << 'X' << " ";
				}else
				{
					out << 'O' << " ";
				}
			}
			
				out << endl; 
		}
				out << "+---------+" <<  endl;	
	}
... I get an error.

Could anyone tell me what I'm doing wrong here?

Could you tell the error first?
Oh yes, sorry about that.
Here:

1>c:\users\nutellajelly\documents\visual studio 2012\projects\pegboard\pegboard\grid.cpp(19): error C3867: 'Grid::getStart': function call missing argument list; use '&Grid::getStart' to
create a pointer to member

1>c:\users\nutellajelly\documents\visual studio 2012\projects\pegboard\pegboard\grid.cpp(19): error C2679: binary '=' : no operator found which takes a right-hand operand of type 'DUPoint (__thiscall Grid::* )(DUPoint) const' (or there is no acceptable conversion)

1> c:\users\nutellajelly\documents\visual studio 2012\projects\pegboard\pegboard\dupoint.h(82): could be 'DUPoint &DUPoint::operator =(const DUPoint &)'

1> while trying to match the argument list '(DUPoint, DUPoint (__thiscall Grid::* )(DUPoint) const)'

1>c:\users\nutellajelly\documents\visual studio 2012\projects\pegboard\pegboard\grid.cpp(20): error C3867: 'Grid::getEnd': function call missing argument list; use '&Grid::getEnd' to create a pointer to member

1>c:\users\nutellajelly\documents\visual studio 2012\projects\pegboard\pegboard\grid.cpp(20): error C2679: binary '=' : no operator found which takes a right-hand operand of type 'DUPoint (__thiscall Grid::* )(DUPoint) const' (or there is no acceptable conversion)

1> c:\users\nutellajelly\documents\visual studio 2012\projects\pegboard\pegboard\dupoint.h(82): could be 'DUPoint &DUPoint::operator =(const DUPoint &)'

1> while trying to match the argument list '(DUPoint, DUPoint (__thiscall Grid::* )(DUPoint) const)'
1>c:\users\nutellajelly\documents\visual studio 2012\projects\pegboard\pegboard\grid.cpp(58): error C3867: 'Grid::isLegalMove': function call missing argument list; use '&Grid::isLegalMove' to create a pointer to member

1>c:\users\nutellajelly\documents\visual studio 2012\projects\pegboard\pegboard\grid.cpp(85): warning C4018: '<' : signed/unsigned mismatch

1>c:\users\nutellajelly\documents\visual studio 2012\projects\pegboard\pegboard\grid.cpp(88): warning C4018: '<' : signed/unsigned mismatch


grid.cpp(19):  error C3867: 'Grid::getStart': function call missing argument list
grid.cpp(20): error C3867: 'Grid::getEnd': function call missing argument list


lines 19 and 20 - getStart and getEnd are functions that each take a parameter. You're missing the parenthesis and parameter when you try to call them on those lines.

Edit:

grid.cpp(19): error C2679: binary '=' : no operator found which takes a right-hand operand of type 'DUPoint 
grid.cpp(20): error C2679: binary '=' : no operator found which takes a right-hand operand of type 'DUPoint


Same lines - What does it mean for a DUPoint to be equal to another DUPoint?
Looks like the overloaded operator in this header file takes a constant DUPoint by reference as an argument.
dupoint.h(82): could be 'DUPoint &DUPoint::operator =(const DUPoint &)'


grid.cpp(58): error C3867: 'Grid::isLegalMove': function call missing argument list


actually line 57 - isLegalMove is a function, you're missing the () and parameters in the function call
Last edited on
Topic archived. No new replies allowed.