operator overloading

Hey guys, I'trying to overload the >> and << operators but a lot errors are coming up and I can't understand a thing.

the word "objeto" means a struct;

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

void acampamento::imprimir(const objeto& dado) {
	cout << dado;
}


ostream& operator<<(ostream& output, const objeto& dado) {
	output << "Identificado: " << dado.id << endl
		   << "Nome: " << dado.nome << endl
		   << "Descricao: " << dado.descricao << endl
		   << "Utilidade: " << dado.utilidade << endl
		   << "Valor: " << dado.valor << endl
		   << "Prioridade: " << dado.prioridade << endl
		   << "Resistencia a agua: " << dado.resistenteAgua << endl
		   << "Durabilidade: " << dado.durabilidade << endl
		   << "Peso: " << dado.peso << endl << endl;
    return output;
}

void acampamento::inserir(fstream& arquivo){  //cria uma objeto
	objeto dado;
	cin >> dado;
	inserir(dado, arquivo);
}

istream& operator>>(istream& input, objeto& dado){
	cout << "ID: ";
	input >> dado.id;
	cout << "Nome: ";
	input >> dado.nome;
	cout << "Descricao: ";
	input >> dado.descricao;
	cout << "Utilidade: ";
	input >> dado.utilidade;
	cout << "Valor: ";
	input >> dado.valor;
	cout << "Prioridade: ";
	input >> dado.prioridade;
	cout << "Resistencia a agua: ";
	input >> dado.resistenteAgua;
	cout << "Durabilidade: ";
	input >> dado.durabilidade;
	cout << "Peso: ";
	input >> dado.peso;

	return input;
}


The error is that:

acampamento.cpp: In member function ‘void acampamento::inserir(std::fstream&)’:
acampamento.cpp:109:6: error: no match for ‘operator>>’ (operand types are ‘std::istream {aka std::basic_istream<char>}’ and ‘objeto’)
cin >> dado;
^
In file included from /usr/include/c++/5/iostream:40:0,
from acampamento.cpp:1:
/usr/include/c++/5/istream:120:7: note: candidate: std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>::__istream_type& (*)(std::basic_istream<_CharT, _Traits>::__istream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]
operator>>(__istream_type& (*__pf)(__istream_type&))


and a buch of thing alike

thanks!

Last edited on
If you try to overload both >> and <<, then why did you post the
ostream& operator<<(ostream& , const objeto& );
twice?

The compiler asks the same question. It cannot see operator>> either.
sorry, I comitted a mistake. check out the code now, I updated it correctly haha
The implementation of operator>> is after the line 22. Has it been declared before anywhere?
Thanks!! I didn't saw it before
Topic archived. No new replies allowed.