problem about printer operator

I have a problem about printer operator defined in the following class:
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
#include<cstring>
#include<iostream>
enum tipo_contatto{CELLULARE,CASA,UFFICIO,FAX,EMAIL};
class Contatto
 {
		tipo_contatto tipo;
		char* numero;
		public:
		Contatto()
		{
			tipo=CELLULARE;
			numero=0;
		}
		Contatto(tipo_contatto t,char* num)
		{
		tipo=t;
		numero=new char[strlen(num)+1];
		strcpy(numero,num); 
		}
		~Contatto()
		{
			if(this->numero!=0)
			delete[](numero);
		}
		Contatto& operator =( const Contatto& altro)
		{
			if(this==&altro) return *this;
			this->tipo=altro.tipo;
			if(this->numero!=0)
			delete[](this->numero);
			this->numero=new char[strlen(altro.numero)+1];
			strcpy(this->numero,altro.numero);
			return *this;
		}
	 friend ostream& operator <<(ostream& output,const Contatto& stampare)
		{
			switch(stampare.tipo)
			{
				case CASA: output <<"CASA:";
				break;
				case CELLULARE: output<<"CELLULARE:";
				break;
				case UFFICIO: output<<"UFFICIO:";
				break;
				case EMAIL: output<<"EMAIL:";
				break;
				default: output<<"unidefined:";
			}
		output<< stampare.numero;
			return output;
		
		}
		bool operator == (const Contatto& altro)
		{
			return (strcmp(this->numero,altro.numero)==0);
		}
		
};

At the time of the execution, the compiler show the following error:
63 133 C:\Users\Gianluca\Documents\progetto1\Persona.h [Error] no match for 'operator<<' in 'std::operator<< <std::char_traits<char> >((* & std::operator<< <std::char_traits<char> >((* & std::operator<< <std::char_traits<char> >((* & std::operator<< <std::char_traits<char> >((* & std::operator<< <std::char_traits<char> >((* & std::operator<< <std::char_traits<char> >((* & std::operator<< <std::char_traits<char> >((* & output), ((const char*)"Nome: "))), ((const char*)persona.Persona::nome))), ((const char*)"\012Cognome: "))), ((const char*)persona.Persona::cognome))), ((const char*)"\012Indirizzo: "))), ((const char*)persona.Persona::indirizzo))), ((const char*)"\012Contatti:")) << persona.Persona::contatti'.
The program Main is the following:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<iostream>
#include "dbLinked.h"
#include "Persona.h"
#include<conio.h>
using namespace std;
int main()
{
	Persona a("Simone","Clementi","padre");
	a.aggiungicontatto(CASA,"355533");
	a.aggiungicontatto(CELLULARE,"3493392928");
	a.aggiungicontatto(EMAIL,"simone@clementi.it");
	Persona b("Gianluca","Maraschio","matteotti");
	Persona c("Greta","Affricani","delmare");
	DbLinked<Persona>lista(a);
	DbLinked<Persona>lista2(b);
	lista2=lista;
	//lista2=lista2+lista;
	cout <<"\n lista di persone:\n" << lista2;
	getch();
	return 0;
}

while the class DbLinked is the following:
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include <iostream>
using namespace std;
template<class T>
class DbLinked
{
	//dato: è la variabile che contiene l'informazione di un certo record
	struct Elemento
	{
			T dato;
			struct Elemento* next;
			struct Elemento* prev;
			Elemento()
			{
				next=0;
				prev=0;
			}
			Elemento(T& elem)
			{
				dato=elem;
				next=0;
				prev=0;
			}
	};
	struct Elemento* start; 
	public: 
	DbLinked()
	{
		this->start=0;
	}
	DbLinked(T& elem)
	{
		this->start=new struct Elemento();
		(this->start)->next=0;
		(this->start)->prev=0;
		(this->start)->dato=elem;
	}	
	~DbLinked()
	{
		struct Elemento* iterator=start;
		struct Elemento* punt;
	
		while(iterator!=0)
		{
			punt=iterator->next;
			cout<<(int) iterator;
			delete(iterator);
			iterator=punt;
		}
		cout<<"\nlista eliminata";
	}
		bool remove(T& elem)
	{
	struct Elemento* iterator;
	if((this->start)->dato==elem)
		{
		iterator=this->start;
		this->start=(this->start)->next;
		if(this->start!=0)
		(this->start)->prev=0;
		delete(iterator);
		return true;
		}
	iterator=start->next;
	while(iterator!=0)
		{			//se il successivo al nodo puntato è uguale ad element
	if(iterator->dato==elem)
			{
			(iterator->prev)->next=iterator->next;
			if(iterator->next!=0)
			(iterator->next)->prev=iterator->prev;
			delete(iterator);
			return true;
			}
	iterator=iterator->next;
		}
	
	return false;
	}
	bool add(T& elem )
	{
	struct Elemento* iterator;
	if(this->start==0) 
		{
		this->start=new struct Elemento();
		(this->start)->dato=elem;
		(this->start)->prev=0;
		(this->start)->next=0;
		return true;
		}	
	iterator=this->start;
	while(iterator!=0)
		{	
	if(iterator->dato==elem) return false;	//non ammessi duplicati
	if(iterator->next==0)
			{
			iterator->next=new struct Elemento(elem);
			(iterator->next)->prev=iterator;
			return true;
			}
	iterator=iterator->next;
		}
return false;
	}
	DbLinked& operator =(const DbLinked& altro)
	{
		struct Elemento* iterator;
		struct Elemento* iterator2;
		iterator=this->start;
		iterator2=altro.start;
		while(iterator2!=0)
		{
			if(iterator!=0)
			{
		 	iterator->dato=iterator2->dato;
			iterator=iterator->next;
			}
			else this->add(iterator2->dato);
			
		iterator2=iterator2->next;
		
		}
		while(iterator!=0)
		{
			iterator2=iterator->next;
			this->remove(iterator->dato);
			iterator=iterator2;
		}
		return *this;
	}
	DbLinked& operator +(const DbLinked& altro)
	{
		DbLinked lista_temp;
		struct Elemento* iterator;
		iterator=this->start;
			while(iterator!=0)
		{
			lista_temp.add(iterator->dato);
			iterator=iterator->next;
		}
		iterator=altro.start;
		while(iterator!=0)
		{
			lista_temp.add(iterator->dato);
			iterator=iterator->next;
		}
		return lista_temp;
	}
	 friend ostream& operator<<(ostream& output,DbLinked& lista)
	{
		int i=0;
		struct Elemento* iterator;
		iterator=lista.start;
		
	while(iterator!=0)
		{	
	output << "\nelemento "<<i<<":\n"<< iterator->dato;	
	i++;
	iterator=iterator->next;
		}
	if(i==0) output << "non ci sono elementi nella lista";
	}
	
	
};


and the class Persona:
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
#include<cstring>
#include<iostream>
#include "Contatto.h"
using namespace std;
class Persona
{
	char* nome;
	char* cognome;
	char* indirizzo;
 DbLinked<Contatto> contatti;
	
	public:
		Persona()
		{
			nome=0;
			cognome=0;
			indirizzo=0;
		}
		Persona(char* n,char* c,char* ind)
		{
			this->nome=new char[strlen(n)+1];
			this->cognome=new char[strlen(c)+1];
			this->indirizzo=new char[strlen(ind)+1];
			strcpy(this->nome,n);
			strcpy(this->cognome,c);
			strcpy(this->indirizzo,ind);
			
		}
		~Persona()
		{
			delete[](nome);
			delete[](cognome);
			delete[](indirizzo);
			cout<<"\npersona eliminata";
			
		}
		void aggiungicontatto(tipo_contatto t,char* num)
		{
			Contatto nuovo_contatto(t,num);
			this->contatti.add(nuovo_contatto);
		}		
		Persona& operator = (const Persona& altro)
		{
		if(this==&altro) return *this;
		delete[](this->nome);
		delete[](this->cognome);
		delete[](this->indirizzo);
		this->nome=new char[strlen(altro.nome)+1];
		this->cognome=new char[strlen(altro.cognome)+1];
		this->indirizzo=new char[strlen(altro.indirizzo)+1];
		strcpy(this->nome,altro.nome);
		strcpy(this->cognome,altro.cognome);
		strcpy(this->indirizzo,altro.indirizzo);
		return *this;
		
		}
		 bool operator == (const Persona& altro)
		{
			return (!strcmp(this->nome,altro.nome)&&!strcmp(this->cognome,altro.cognome)&&!strcmp(this->indirizzo,altro.indirizzo));
		}
		friend ostream& operator <<(ostream& output,const Persona& persona) 
		{
			output<<"Nome: "<< persona.nome<<"\nCognome: "<< persona.cognome<<"\nIndirizzo: "<<persona.indirizzo << "\nContatti:" << persona.contatti;
			return output;
		}
		
		
};


In the class Persona,within the function that it defines the printer operator, without << persona.contatti the program run correctly.

Help me!!
Thanks in advance
the problem is that you don't have const for the operator<< in DbLinked (persona.contatti is const)

you forgot the const for other operator as well
Topic archived. No new replies allowed.