积极答复者
让人很纠结的一个问题

问题
-
struct Addesslist one={"liming","3786121",ffc@.qq.com};
另外的一个方案:
string bb={"liming","3786121",ffc@.qq.com};
struct Addesslist one=bb; //不能这么写,这里如果用重载,不知道怎么做,最好不要用strtok; 用下面的方式,谁能给出一段代码吗? thanks Addesslist &Addesslist::operator=(Addesslist *p)
- 已编辑 lucy-liuModerator 2011年2月14日 7:53 增加可读性
答案
-
在Addesslist中,写一个string的构造函数。
麻烦把正确答案设为解答。- 已标记为答案 Honny_yeyh 2011年3月11日 12:27
全部回复
-
Addesslist bb={"liming","3786121","ffc@.qq.com"}; struct Addesslist one=bb;
而不是
string bb={"liming","3786121","ffc@.qq.com"}; struct Addesslist one=bb;
吧
Addesslist &Addesslist::operator=(const Addesslist& value)
{
if(this == &value)
{
return *this;
}
// your copy operation
return *this;
}
麻烦把正确答案设为解答。- 已建议为答案 Peter_Yu 2011年2月14日 3:16
-
Addesslist bb={"liming","3786121","ffc@.qq.com"}; struct Addesslist one=bb; //这里={"liming","3786121","ffc@.qq.com"}; 是从网络接收的数据,是动态的,所以只能是string类型,或者用scanf可以转换,其实这就是这个问题的核心的地方
而不是
string bb={"liming","3786121","ffc@.qq.com"}; struct Addesslist one=bb;
吧
Addesslist &Addesslist::operator=(const Addesslist& value)
{
if(this == &value)
{
return *this;
}
// your copy operation
return *this;
}
-
所以说回到我的第一个问题:
string bb={"liming","3786121",ffc@.qq.com};
struct Addesslist one=bb; // 这里怎么赋值的问题, 上面string不变
-
在Addesslist中,写一个string的构造函数。
麻烦把正确答案设为解答。- 已标记为答案 Honny_yeyh 2011年3月11日 12:27