#define LOG(format,...) Logger::Log(format,__VA_ARGS__)
#define STRIP(netIp) GeneralUtils::inet_ntop_(netIp)
string GeneralUtils::inet_ntop_(unsigned int netIp){
char strIP[INET_ADDRSTRLEN];
in_addr sin_addr;
sin_addr.s_addr = netIp;
inet_ntop(AF_INET, &sin_addr.s_addr, strIP, sizeof strIP);
return string(strIP);
}
致电时:
LOG("src %s dst %s" ,STRIP(src_ip_));
我得到编译错误:
cannot pass objects of non-trivially-copyable type ‘std::string {aka struct std::basic_string<char>}’ through ‘...’
我知道 varargs 是 c 兼容的,所以我不能向它发送字符串。有没有简单的方法绕过它?像这样修复它是否正确:
#define STRIP(netIp) GeneralUtils::inet_ntop_(netIp).data()