overload "<<" iterator (using by Vector)

Hello.
First, hellow, i'm a new hare.
Second, my english is not perfect so i'm apology for spelling mistakes.

Third, hare is my cuation:

I'm trying to overload the operator "<<" in iterator "Inner class"
that using in VECTOR interface.

hare is the syntax of the overload operator.
the error that i'm get is:

"member "Vector<T>::iterator::one" is inaccessible"
"member "Vector<T>::iterator::data" is inaccessible"
"identifier "index" is underfined"

Lot of thanks above


1
2
3
4
friend ostream & operator << (ostream & out, const iterator & it)
{
	return out << it.one.data[index];
}


hare is the full code:
(note: "student" is some class that i create")
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 "student.h"
#include <iostream>
using namespace std;

//const int DEF_CAPACITT = 100;

//------------------------------------
// Vector <T> class
//------------------------------------
template <class T>
class Vector
{
private:

    T * data;
    int size;		//size in use
    int capacity;	//available capacity

public:
    //constructors
	Vector(int capacity = 100);
	Vector(const Vector <T> &);
	~Vector();

	// operators and functions
    Vector & operator = (const Vector <T> &); 
    T & operator [] (int index);
    const T & operator [] (int index) const;
	int	Size		() const;
	int  Capacity	() const;
	void Insert		(T value);
	void  Clear		();
	T DelLast	();
	
	friend class itarator;

	//------------------------------------
	// ITERATOR inner class
	//------------------------------------
	
	class iterator
	{
		
		Vector & one;
		int index;

	public:
	
		iterator (Vector &);		// constructor for Begining
			//: one(A) , index(0)			{}
		iterator (Vector & , bool);	// constructor for End
			//: one(A) , index(size)		{}

		student operator ++ ();
		//int operator ++ (int) ;
		student operator -- ();
		student operator += (int);
		student operator -= (int);
		bool operator == (iterator  &);
		bool operator != (iterator  &);

		friend ostream & operator << (ostream & out, const iterator & it)
		{
			return out << it.one.data[index];
		}

		//student current () const { return one.data[index]; }
		
	};

	iterator begin()	{	return iterator (*this);		}
	iterator end()		{	return iterator (*this,true);	}


};


Last edited on
The problem not solve yet.

I will be happy to got a answer
data is a private field of Vector. So operator<< cannot access it.
Thank you for the answer.
it is was one of the problems...

Solution for your problems is to use public Vector interface: say, operator[]
Topic archived. No new replies allowed.