
problema para genios con clase
Publicado por Jonatan Urán (2 intervenciones) el 17/10/2007 02:09:59
//por qué no es posible hacer esto? aparentemente todo está bien escrito
//CLASS AUTOMOVIL Y CAMION
/* El problema está en la funcion compara perteneciente a la clase camion el compilador me dice que dicha función no es miembro de la clase camión */
#include <iostream.h>
class camion; //forward
class automovil
{
private: float vel;
public: automovil(){}
automovil(float);
void mostrar();
void compara(const camion &);
///////
friend void camion::compara(const automovil &);
////////
};
class camion
{
private: float vel;
public: camion(){}
camion(float);
void mostrar();
friend void automovil::compara(const camion &);
//////////
void compara(const automovil &);
//////////
};
automovil::automovil(float vel)
{this->vel=vel;}
camion::camion(float vel)
{this->vel=vel;}
void automovil::mostrar()
{cout <<"velocidad: " <<vel <<endl;}
void camion::mostrar()
{cout <<"velocidad: " <<vel <<endl;}
void automovil::compara(const camion &c)
{
if(vel > c.vel)
cout <<"auto mas rapido" <<endl;
else
if(vel < c.vel)
cout <<"camion mas rapido" <<endl;
else
cout <<"velocidades iguales" <<endl;
}
////////////////
void camion::compara(const automovil &a)
{
if(vel > a.vel)
cout <<"camion mas rapido" <<endl;
else
if(vel < a.vel)
cout <<"auto mas rapido" <<endl;
else
cout <<"velocidades iguales" <<endl;
}
////////////////////
void main()
{
automovil a1(150),a2;
camion c1(120),c2;
a1.mostrar();
a2.mostrar();
c1.mostrar();
c2.mostrar();
a2.compara(c2);
/////////////
c2.compara(a2);
///////////
cin.get(); cin.get();
}
//CLASS AUTOMOVIL Y CAMION
/* El problema está en la funcion compara perteneciente a la clase camion el compilador me dice que dicha función no es miembro de la clase camión */
#include <iostream.h>
class camion; //forward
class automovil
{
private: float vel;
public: automovil(){}
automovil(float);
void mostrar();
void compara(const camion &);
///////
friend void camion::compara(const automovil &);
////////
};
class camion
{
private: float vel;
public: camion(){}
camion(float);
void mostrar();
friend void automovil::compara(const camion &);
//////////
void compara(const automovil &);
//////////
};
automovil::automovil(float vel)
{this->vel=vel;}
camion::camion(float vel)
{this->vel=vel;}
void automovil::mostrar()
{cout <<"velocidad: " <<vel <<endl;}
void camion::mostrar()
{cout <<"velocidad: " <<vel <<endl;}
void automovil::compara(const camion &c)
{
if(vel > c.vel)
cout <<"auto mas rapido" <<endl;
else
if(vel < c.vel)
cout <<"camion mas rapido" <<endl;
else
cout <<"velocidades iguales" <<endl;
}
////////////////
void camion::compara(const automovil &a)
{
if(vel > a.vel)
cout <<"camion mas rapido" <<endl;
else
if(vel < a.vel)
cout <<"auto mas rapido" <<endl;
else
cout <<"velocidades iguales" <<endl;
}
////////////////////
void main()
{
automovil a1(150),a2;
camion c1(120),c2;
a1.mostrar();
a2.mostrar();
c1.mostrar();
c2.mostrar();
a2.compara(c2);
/////////////
c2.compara(a2);
///////////
cin.get(); cin.get();
}
Valora esta pregunta


0