Ver Mensaje Individual
  #1 (permalink)  
Antiguo 22/08/2005, 17:20
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
Ayuda con sobrecarga de operadores en C++

Tengo que hacer una clase que permite concatenar cadenas, luego de leer durante horas un libro de c++ me las arregle para hacer esto, compila perfecto en DEV C++ sin embargo cuando lo ejecuto me tira error y se me cierra, incluso hice copy & paste del programa del libro y tambien da error, aqui dejo lo que hice yo, es simple:

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);
	    Str operator =(Str);
	    void view();
};    
#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 =(Str s)
{
    strcpy(string, s.string);
    return *this;
}
void Str::view()
{
    cout << string;
}
main.cpp
Código:
#include "string.h"
#include <iostream>
#include <stdlib.h>

using namespace std;

int main()
{
  Str str1("Hola "), str2("Mundo"), str3;
  str3 = str1 + str2;
  str3.view();
  system("PAUSE");	
  return 0;
}
que esta mal???