Programación General > Visual C++
Visual C++ 7.1 (mvs .net 2003) Y Clases
Eternal Idol:
--- Cita de: "JoGalGar" --- Muchísimas gracias por tu tiempo!!! Arigatou!!!!
--- Fin de la cita ---
De nadas :ph34r:
JoGalGar:
Hola de nuevo. Tengo otro problema. Cree un mensaje en OMNeT++ llamado IPDatagram.msg. El compilador de OMNeT++ lo cambia a IPDatagram_m.h e IPDatagram_m.cpp. Con estos archivos se genera, digamos, una clase tipo IPDatagram donde por medio del "get" y el "set" se adquieren o establecen, respectivamente, valores dentro del mensaje .msg. En este caso, necesito que tanto srcip como destip cambien a tipo string. Ya realzié lo siguiente (el código está al final):
string a = srcip;
Y me marcó el siguiente error:
... cannot convert from 'IPDatagram *' to 'std::basic_string<_Elem,_Traits,_Ax>'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]
No constructor could take the source type, or constructor overload resolution was ambiguous
Podrías ayudarme a cambiar de IPDatagram * a un entero? Gracias.
void IP::handlemessage(cMessage *msg)
{
pktsin++;
IPDatagram *srcip = new IPDatagram();
srcip -> getSrcAddress();
IPDatagram *destip = new IPDatagram();
destip -> getDestAddress();
IPDatagram *ttl = new IPDatagram();
ttl -> setTtl(ttl -> getTtl()-1);
rta = new Routingtable();
rta->findroute(srcip);
}
Eternal Idol:
Estoy viendo la documentacion en:
http://www.omnetpp.org/doc/INET/doxy/class_i_p_datagram.html
tanto srcAddress como destAddress son del tipo IPAddress que tiene un metodo llamado str ... entonces supongo que con esto te funcionara:
--- Código: Text --- string a = srcip->srcAddress.str();
JoGalGar:
Muchas gracias. No funcionó bien, me dice el siguiente error:
IP.cpp(31) : error C2228: left of '.str' must have class/st
type is 'IPDatagram *'
did you intend to use '->' instead?
Intenté lo siguiente:
ostringstream sA;
IPDatagram *srcip = new IPDatagram();
srcip -> getSrcAddress();
sA<<srcip;
string A = sA.str();
rta = new Routingtable();
rta->findroute(A);
Y ya no me marcó error la compilación ... en teoría sí lo hice bien. Ahora, no sé como hacer un proceso similar pero para cambiarlo a int. Gracias por tu tiempo.
Eternal Idol:
--- Cita de: "JoGalGar" --- Muchas gracias. No funcionó bien, me dice el siguiente error:
IP.cpp(31) : error C2228: left of '.str' must have class/st
type is 'IPDatagram *'
did you intend to use '->' instead?
--- Fin de la cita ---
Bueno, la documentacion no es muy exacta entonces ya que dice IPAddress y no *IPAddress, tendrias que haber puesto lo mismo pero con ->str(). El int lo tenes ahi igual de facil:
--- Código: Text --- int ip = srcip->srcAddress->getInt();
Navegación
[#] Página Siguiente
[*] Página Anterior
Ir a la versión completa