鉴于此代码:
void group::build(int size, std::string *ips){
/*Build the LL after receiving the
member list from bootstrap*/
head = new member("head");
member *temp1,*temp2;
temp1 = new member(ips[0].data()); // error here
// ....
}
member::member(char *ip){
strcpy_s(this->ip_addr,sizeof(ip),ip);
this->next = NULL;
this->previous = NULL;
}
指向字符串的指针定义为:
std::string *ips;
我想初始化数组,ips
使用字符串,但是当我尝试从任何数组成员获取字符数据时,我收到错误:
无法将参数转换为const char *
to char *
Why?
您调用的函数需要一个指向可修改缓冲区的指针,char*
。您正在传递一个指向不可修改缓冲区的指针,const char*
.
自从你的member
函数不会修改其输入,您应该更改其声明以接收const char*
.
member::member(const char *ip)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)