Linker error, set up correctly

Hello, i've been having these linker errors:
Error 5 error LNK1120: 2 unresolved externals C:\college\Year 3\Year 3\Semester 1\Programming\Formal report\Grid\Debug\Grid.exe
1

Error 4 error LNK2019: unresolved external symbol "class std::basic_istream<char,struct std::char_traits<char> > & __cdecl operator>>(class std::basic_istream<char,struct std::char_traits<char> > &,class grid &)" (??5@YAAAV?$basic_istream@DU?$char_traits@D@std@@@std@@AAV01@AAVgrid@@@Z) referenced in function _main C:\college\Year 3\Year 3\Semester 1\Programming\Formal report\Grid\Grid\GridClass.obj


Error 3 error LNK2019: unresolved external symbol "class std::basic_istream<char,struct std::char_traits<char> > & __cdecl operator>>(class std::basic_istream<char,struct std::char_traits<char> > &,class supergrid &)" (??5@YAAAV?$basic_istream@DU?$char_traits@D@std@@@std@@AAV01@AAVsupergrid@@@Z) referenced in function _main C:\college\Year 3\Year 3\Semester 1\Programming\Formal report\Grid\Grid\GridClass.obj


I'm certain that the initial set up is done correctly(win 32 console etc) as i've done it many times before. I just cannot find out what is wrong with the code
Thank you

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
  #include <iostream>
#include <fstream>

const int gridrows = 5;
const int gridcols = 6;

using namespace std;

class grid
{
public:

	int powergrid[gridrows][gridcols];

	friend ostream& operator <<(ostream&,const grid&);
	friend istream& operator >>(istream&,grid&);

	grid()
	{
		int i,j;
		for (i=0;i<gridrows;i++)
		{	for(j=0; j<gridcols; j++)
			{powergrid[i][j];}
		}
		
	}

	int powerok();
	void whereoff();
	

};

int grid::powerok()
{
		int ok = 1;
		int i,j;

		for (i=0;i<gridrows &&ok; i++) //row count
		{ for (j=0;j<gridcols && ok;j++) //col count
			{ if (powergrid[i][j] != 1)
			ok=0; }
		return(ok);
		}                       //outage
}

void grid::whereoff()
{
	int i,j;
	cout << "\n\nPower off in grid cells: \n";
	for (i=0;i<gridrows;i++)
	{cout<< endl;}
	for(j=0;j<gridcols; j++)
		{ if (powergrid[i][j] != 1)
			{ cout<< "\nPower in " << i <<" " << j<< " "<< "is "<< powergrid[i][j] << endl;}
		}
}
ostream& operator << (ostream &os,const grid& GR)
{
int i,j;
	for(i=0;i<gridrows;i++)
		{ for (j=0; j<gridcols;j++)
			{os<<" " << GR.powergrid[i][j];}
		}
	return os;
}

istream& operator << (istream &is,  grid& GR)
{
int i,j;
	for(i=0;i<gridrows;i++)
		{ for (j=0; j<gridcols;j++)
			{is>> GR.powergrid[i][j];}
		}
	return is;
}

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
class supergrid:public grid
{
public:
	int powergrid[gridrows][gridcols];

	friend ostream& operator <<(ostream&,const supergrid&);
	friend istream& operator >>(istream&,supergrid&);
	supergrid()
	{
		int i,j;
		for (i=0;i<gridrows;i++)
		{	for(j=0; j<gridcols; j++)
			{powergrid[i][j];}
		}
		
	}

	int powerok();
	void whereoff();
};

int supergrid::powerok()
{
		int ok = 1;
		int i,j;

		for (i=0;i<gridrows &&ok; i++) //row count
		{ for (j=0;j<gridcols && ok;j++) //col count
			{ if (powergrid[i][j] != 1)
			ok=0; }
		return(ok);
		}                       //outage
}

void supergrid::whereoff()
{
	int i,j;
	cout << "\n\nPower off in grid cells: \n";
	for (i=0;i<gridrows;i++)
	{cout<< endl;}
	for(j=0;j<gridcols; j++)
		{ if (powergrid[i][j] != 1)
			{ cout<< "\nPower in " << i <<" " << j<< " "<< "is "<< powergrid[i][j] << endl;}
		}
}
ostream& operator << (ostream &os,const supergrid& GR)
{
int i,j;
	for(i=0;i<gridrows;i++)
		{ for (j=0; j<gridcols;j++)
			{os<<" " << GR.powergrid[i][j];}
		}
	return os;
}

istream& operator << (istream &is,  supergrid& GR)
{
int i,j;
	for(i=0;i<gridrows;i++)
		{ for (j=0; j<gridcols;j++)
			{is>> GR.powergrid[i][j];}
		}
	return is;
}

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
void main()
{	
	
grid myG;
	char file_name[13]; 

	cout <<"Grid Data" << myG;
	cout <<"\n\nEnter file name: ";
	cin >> file_name;

	ofstream outfile(file_name,ios::out);
		if (outfile!=NULL){
			outfile <<myG;
			outfile.close();}
		else{cout <<"\n Cannot open file" << file_name;}

		cout << "\nEnter the "<< gridrows << " x " << gridcols<<" data = \n";
		cin>>myG;
		cout<<"\nPower grid data" << myG;

		ifstream infile(file_name,ios::in);
		if(infile!=NULL){
			infile >>myG;
			cout <<"\n\nPower grid data from file\n" <<myG;
			infile.close();}
		else {cout<<"\nCannot open file " << file_name;}

		cout << "\nEnter values for my grid" << endl;
		cin >> myG;

		if (myG.powerok())
				cout <<"\nPower is ok throughout grid";
		else
				myG.whereoff();
				

		//-------------------------------------------------------Super Grid
	supergrid mySuperG;
	char file_name2[13]; 

	cout <<"Grid Data" << mySuperG;
	cout <<"\n\nEnter file name: ";
	cin >> file_name2;

	ofstream outfile2(file_name2,ios::out);
		if (outfile2!=NULL){
			outfile2 <<mySuperG;
			outfile2.close();}
		else{cout <<"\n Cannot open file" << file_name2;}

		cout << "\nEnter the "<< gridrows << " x " << gridcols<<" data = \n";
		cin>>mySuperG;
		cout<<"\nPower grid data" << mySuperG;

		ifstream infile2(file_name2,ios::in);
		if(infile2!=NULL){
			infile2 >>mySuperG;
			cout <<"\n\nPower grid data from file\n" <<mySuperG;
			infile2.close();}
		else {cout<<"\nCannot open file " << file_name2;}

		if (mySuperG.powerok())
				cout <<"\nPower is ok throughout grid";
		else
				mySuperG.whereoff();
}
grid.h line 68, supergrid.h line 56.
You have the wrong operator (<<). Should be >>.
Thank you abstractionAnon,

facedesking right now
Topic archived. No new replies allowed.