我有
run(){
...
struct sockaddr_in from;
int i = recvpacket(buffer,from, fromlen)
...
}
recvpacket(char *buffer, struct sockaddr_in from, int fromlen)
{
//udp recvfrom stores the address of the sender in from
}
我在VC ++中得到以下运行时错误
runtime check failure - the variable 'from' is used without being initialized
我应该通过引用传递,我应该怎么做?
答案 0 :(得分:2)
要解决两件事:
删除您必须初始化from
的警告,例如:
struct sockaddr_in from= {0};
在调用recvpacket
时获取地址,您必须通过引用声明它
recvpacket(char *buffer, struct sockaddr_in& from, int fromlen)
答案 1 :(得分:1)
在你的run()方法中:struct sockaddr_in from = {0};
并通过引用传递它以在被调用方法中更新