The_Punisher
22/06/2015, 12:01
Buenas gente!
Estoy empezando con C++ y voy leyendo un libro y haciendo ejercicios, pero me he quedado aquí un poco atascado y no encuentro exactamente una solución a este error.
Es en la última línea al intentar borrar el array, igual es una tontería pero no se que estoy haciendo mal.
A ver si me podeís echar una mano, un saludo!
#include <iostream>
using namespace std;
class Telefono {
string numero;
float importe;
string tarifa;
string nombre;
public:
Telefono (); //constructor por defecto
Telefono (string _numero); //constructor parametrizado
Telefono (const Telefono &tel);
Telefono (string _numero, string _tarifa, string _nombre);
void mostrar();
~Telefono (); //destructor
void actualizarImporte(int _importe);
void mostarImporte();
float obtenerImporte();
};
Telefono::Telefono () {
importe = 0;
numero="985541318";
cout <<"Constructor por defecto"<<endl;
}
Telefono::Telefono (string _numero) {
numero=_numero;
importe=0;
cout <<"Constructor parametrizado"<<endl;
}
Telefono::Telefono (string _numero, string _tarifa, string _nombre) {
numero=_numero;
tarifa=_tarifa;
nombre=_nombre;
importe=0;
cout <<"Constructor parametrizado"<<endl;
}
Telefono::Telefono (const Telefono &tel) {
importe=tel.importe;
cout <<"Constructor copia"<<endl;
}
void Telefono::mostrar() {
cout<<"Numero :"<<numero<<endl;
}
void Telefono::mostarImporte(){
cout<<"Importe: "<<importe<<endl;
}
void Telefono::actualizarImporte(int _importe){
importe=_importe;
}
float Telefono::obtenerImporte(){
return importe;
}
Telefono::~Telefono () {
cout <<"Destructor"<<endl;
}
int main() {
Telefono telefono1;
Telefono telefono2("927123456");
Telefono *telefono3 = new Telefono("927123456", "Di", "Juan");
telefono3->mostarImporte();
telefono3->actualizarImporte(30);
telefono3->mostarImporte();
telefono1.mostrar();
telefono2.mostrar();
telefono3->mostrar();
telefono1.mostrar();
telefono2.mostrar();
Telefono *telefono4[2];
telefono4[0] = new Telefono("927654321", "No", "María Paz");
telefono4[0]->actualizarImporte(20);
cout << "Importe: " << telefono4[0]->obtenerImporte() << endl;
telefono4[0]->mostrar();
telefono4[1] = new Telefono("927555555", "No", "Jesús Sanz");
telefono4[1]->actualizarImporte(50);
cout << "Importe: " << telefono4[1]->obtenerImporte() << endl;
telefono4[1]->mostrar();
telefono4[0]->mostrar();
telefono4[1]->mostrar();
cout<<"Hola telefono 3"<<endl;
delete telefono3;
cout<<"Adios telefono 3"<<endl;
cout<<"Hola telefono 4"<<endl;
delete[] telefono4; //Aquí casca :(
cout<<"Adios telefono 4"<<endl;
}
Estoy empezando con C++ y voy leyendo un libro y haciendo ejercicios, pero me he quedado aquí un poco atascado y no encuentro exactamente una solución a este error.
Es en la última línea al intentar borrar el array, igual es una tontería pero no se que estoy haciendo mal.
A ver si me podeís echar una mano, un saludo!
#include <iostream>
using namespace std;
class Telefono {
string numero;
float importe;
string tarifa;
string nombre;
public:
Telefono (); //constructor por defecto
Telefono (string _numero); //constructor parametrizado
Telefono (const Telefono &tel);
Telefono (string _numero, string _tarifa, string _nombre);
void mostrar();
~Telefono (); //destructor
void actualizarImporte(int _importe);
void mostarImporte();
float obtenerImporte();
};
Telefono::Telefono () {
importe = 0;
numero="985541318";
cout <<"Constructor por defecto"<<endl;
}
Telefono::Telefono (string _numero) {
numero=_numero;
importe=0;
cout <<"Constructor parametrizado"<<endl;
}
Telefono::Telefono (string _numero, string _tarifa, string _nombre) {
numero=_numero;
tarifa=_tarifa;
nombre=_nombre;
importe=0;
cout <<"Constructor parametrizado"<<endl;
}
Telefono::Telefono (const Telefono &tel) {
importe=tel.importe;
cout <<"Constructor copia"<<endl;
}
void Telefono::mostrar() {
cout<<"Numero :"<<numero<<endl;
}
void Telefono::mostarImporte(){
cout<<"Importe: "<<importe<<endl;
}
void Telefono::actualizarImporte(int _importe){
importe=_importe;
}
float Telefono::obtenerImporte(){
return importe;
}
Telefono::~Telefono () {
cout <<"Destructor"<<endl;
}
int main() {
Telefono telefono1;
Telefono telefono2("927123456");
Telefono *telefono3 = new Telefono("927123456", "Di", "Juan");
telefono3->mostarImporte();
telefono3->actualizarImporte(30);
telefono3->mostarImporte();
telefono1.mostrar();
telefono2.mostrar();
telefono3->mostrar();
telefono1.mostrar();
telefono2.mostrar();
Telefono *telefono4[2];
telefono4[0] = new Telefono("927654321", "No", "María Paz");
telefono4[0]->actualizarImporte(20);
cout << "Importe: " << telefono4[0]->obtenerImporte() << endl;
telefono4[0]->mostrar();
telefono4[1] = new Telefono("927555555", "No", "Jesús Sanz");
telefono4[1]->actualizarImporte(50);
cout << "Importe: " << telefono4[1]->obtenerImporte() << endl;
telefono4[1]->mostrar();
telefono4[0]->mostrar();
telefono4[1]->mostrar();
cout<<"Hola telefono 3"<<endl;
delete telefono3;
cout<<"Adios telefono 3"<<endl;
cout<<"Hola telefono 4"<<endl;
delete[] telefono4; //Aquí casca :(
cout<<"Adios telefono 4"<<endl;
}