what's meaning?

wizardblue 2004-12-03 07:05:27
struct Edge{
int w,v;
Edge(int v=-1,int w=-1) : v(v), w(w){ }//? what's meaning?
};
...全文
164 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jinhao 2004-12-03
  • 打赏
  • 举报
回复
struct Edge{
int w,v;
Edge(int v=-1,int w=-1)
{
v=v; //oops
w=w; //oops
}
};

struct Edge{
int w,v;
Edge(int v=-1,int w=-1)
{
this->v=v; //oops
this->w=w; //oops
}
};
ck2205 2004-12-03
  • 打赏
  • 举报
回复
给成员变量赋值.
snow810211 2004-12-03
  • 打赏
  • 举报
回复
构造函数
struct Edge{
int w,v;
Edge(int v=-1,int w=-1) : v(v), w(w){ }
};

也可以写成:

struct Edge{
int w,v;
Edge(int v=-1,int w=-1)
{
v=v;
w=w;
}
};

Jinhao 2004-12-03
  • 打赏
  • 举报
回复
sorry, my mistake. the data member v and parameter v are right here
Jinhao 2004-12-03
  • 打赏
  • 举报
回复
there is a mistake in your code, same names, w and v

struct Edge{
int w_,v_;

Edge(int v=-1,int w=-1) //this is a contructor
: v_(v), w_(w) //this is member initialization list, it provides a mechanism than you can direct-initialize the objects of class type.
{ }
};
pcyy 2004-12-03
  • 打赏
  • 举报
回复
楼主:
you should say:what's the meaning or what's mean.
wizardblue 2004-12-03
  • 打赏
  • 举报
回复
i means why here do thus?
insulator 2004-12-03
  • 打赏
  • 举报
回复
v(v), w(w)
======>v=v;w=w;

64,637

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧