I'm trying to declare pointer to class at one function, and call another function with this pointer as parameter. Another function trying to create class and assign pointer to this new created class to input pointer.
First method:
size_t packetLen = 0;
ETH2::PacketEthernetII* eth = NULL;
IPv4::PacketIPv4* ip4 = NULL;
ICMP::PacketICMP* icmp = NULL;
TCP::PacketTCP* tcp = NULL;
UDP::PacketUDP* udp = NULL;
if (!buildPackets(formats, packetLen, eth, ip4, icmp, tcp, udp)) {}
Another method:
bool Device::buildPackets(const Tokens& formats, size_t& packetLen,
ETH2::PacketEthernetII* eth, IPv4::PacketIPv4* ip4,
ICMP::PacketICMP* icmp, TCP::PacketTCP* tcp, UDP::PacketUDP* udp)
{
for (size_t i = 0; i < formats.size(); ++i) {
if (Utilities::startsWith(formats[i], ETH2PROTO)) {
eth = createEthernet2(formats[i]);
if (!eth)
return false;
packetLen += eth->len();
}
}
return true;
}
Second method is working and eth takes value to the object. But after return to first method, eth is null... And I don't know why. What important detail about pointers I missed?