#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);
}
打電話來時:C++傳遞字符串可變參數
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 ‘...’
據我所知,可變參數爲c兼容,所以我不能發送字符串給它。 有沒有簡單的方法來繞過它? 會不會是正確的解決這樣的:
#define STRIP(netIp) GeneralUtils::inet_ntop_(netIp).data()
而不是在'STRIP'宏中使用'data'(或'c_str'),你可以在LOG調用中使用它:LOG(「src%s dst%s」,STRIP(src_ip_))。 '# –
@Joachim Pileborg我preffer修復一個地方,並不是所有的這個調用放到LOG –