Ver Mensaje Individual
  #15 (permalink)  
Antiguo 23/08/2005, 18:13
Avatar de SiR.CARAJ0DIDA
SiR.CARAJ0DIDA
 
Fecha de Ingreso: junio-2004
Ubicación: Acá
Mensajes: 1.166
Antigüedad: 20 años, 8 meses
Puntos: 4
es la misma clase que use al principio del thread, aqui pongo todo completo de nuevo:

string.h
Código:
#ifndef STRING_H
#define STRING_H
#include <iostream>

using namespace std;

class Str
{
	char string[100];

	public:
	    Str(char *s = "\0")
	    {
	        strcpy(string, s);
	    }
 	    ~Str() { };
	    Str operator +(Str);	// concatena 2 objetos
	    Str operator +(char[]);	// concatena objeto con cadena
	    friend ostream& operator << (ostream&, const Str&);
	    friend istream& operator >> (istream&, const Str&);
	    Str operator =(Str);
	    Str operator =(char[]);
};    
#endif
string.cpp
Código:
#include "string.h"
#include <iostream>
Str Str::operator +(Str s)
{
    Str tmp;
	strcpy(tmp.string, string);
	strcat(tmp.string, s.string);
	return tmp;
}
Str Str::operator +(char s[])
{
	Str tmp;
	strcpy(tmp.string, string);
	strcat(tmp.string, s);
	return tmp;
}
Str Str::operator =(Str s)
{
    strcpy(string, s.string);
    return *this;
}
Str Str::operator =(char s[])
{
	strcpy(string, s);
	return *this;
}
ostream& operator << (ostream &f, const Str &obj)
{
	f << obj.string << endl;
	return f;
}
istream& operator >> (istream &f, const Str &obj)
{
	f >> obj.string;
	return f;
}
main.cpp
Código:
#include "string.h"
#include <iostream>
#include <stdlib.h>

using namespace std;

int main()
{
  Str str1("CaraJodida "), str2("es groso "), str3;
  str3 = str1 + str2;
  str3 = str3 + ";D ";
  cout << "Cadena concatenada: " << str3 << endl;
  str3 = "cadena asignada a objeto";
  cout << "Otra cadena: " << str3 << endl;
  //cout << "Ingrese cadena : ";
  //cin >> str3;
  cout << str3;
  system("PAUSE");	
  return 0;
}
El error que tira es:
34 G:\C++\Projects LP3\string\string.cpp ambiguous overload for 'operator>>' in 'f >> obj->Str::string'