Overloading <<

When I had my code on one big page is was working fine but as soon as a try to organize it and make a header and cpp file for my class I ran into an issue with the overload for <<. It gives me a bunch of errors on line 19 column 1 of my intArray.h file;

error C2143: syntax error : missing ';' before '&'
error C2433: 'ostream' : 'friend' not permitted on data declarations
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2061: syntax error : identifier 'ostream'
error C2805: binary 'operator <<' has too few parameters

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
// intArray.h

#include <iostream>
#include <fstream>

#ifndef _ZIPCODE_H
#define _ZIPCODE_H

class IntArray{
public:
	IntArray();
	IntArray(int h);
	IntArray(int l, int h);

	int high();
	int low();
	void setName(const char* a);
	int& operator[] (const int i);
	friend ostream& operator<<(ostream& is, IntArray& ia);
private:
	const char* name;
	int h;
	int l;
	int intAray[10];
	int offset;
};


#endif

// intArray.cpp 
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdlib.h>
#include "intArray.h"

using namespace std;


ostream& operator<<(ostream& os, IntArray& ia){
	for (int i = ia.l; i <= ia.h; i++){
		cout << i << " " << ia.offset << " " << i + ia.offset << endl;
		cout << ia.name << "[" << i << "] = " << ia.intAray[i + ia.offset] << endl;
	}
	return os;
}

IntArray::IntArray(){
	h = 10;
	l = 0;
	offset = 0;
}

IntArray::IntArray(const int high){
	h = high;
	l = 0;
	offset = l * -1;
}

IntArray::IntArray(const int low, const int high){
	h = high;
	l = low;
	offset = l * (-1);
}

int& IntArray::operator[] (const int i){
	if (l <= i && h >= i){
		return intAray[i + offset];
	}
	else{
		cout << "error" << endl;
		return intAray[h + 1];
	}
}

int IntArray::high(){
	return h;
}

int IntArray::low(){
	return l;
}

void IntArray::setName(const char* a){
	name = a;
}
friend std::ostream& operator<<(std::ostream& is, IntArray& ia);
Topic archived. No new replies allowed.