求助struct!!!

wo0dy 2010-03-13 10:38:39
struct ME_Sample
{
public:
ME_Sample() :label("") {};//
ME_Sample(const std::string &l) : label(l) {};
void set_label(const std::string & l)
{
label = l;
}

// to add a binary feature
void add_feature(const std::string & f)
{
features.push_back(f);
}

// to add a real-valued feature
void add_feature(const std::string & s, const double d)
{
rvfeatures.push_back(std::pair<std::string, double>(s, d));
}

public:
std::string label;
std::vector<std::string> features;
std::vector<std::pair<std::string, double> > rvfeatures;

// obsolete
void add_feature(const std::pair<std::string, double> & f)
{
rvfeatures.push_back(f); // real-valued features
}
};
网上找的一个工具包,这段结构不太懂
ME_Sample() :label("") {};能给我解释下这个声明么?是使用结构体名声明的函数么?
ME_Sample(const std::string &l) : label(l) {};
还有这个。。
...全文
80 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
BT六眼飞鱼 2010-03-13
  • 打赏
  • 举报
回复
ME_Sample() :label("") {};
ME_Sample(const std::string &l) : label(l) {};
冒号后面的一般被称为 初始化列表
某某9 2010-03-13
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 thefirstz 的回复:]

ME_Sample() :label("") {}; ———— ME_Sample结构继承自lable结构,这是构造函数的写法
下面的也是
[/Quote]哦!
BT六眼飞鱼 2010-03-13
  • 打赏
  • 举报
回复
ME_Sample() :label("") {};
ME_Sample(const std::string &l) : label(l) {};
都是构造函数在被调用之前的,成员数据初始化,比调用构造函数进行赋值运算要快。
yuzl32 2010-03-13
  • 打赏
  • 举报
回复
ME_Sample() :label("") //初始化成员
昵称很不好取 2010-03-13
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 thefirstz 的回复:]
ME_Sample() :label("") {}; ———— ME_Sample结构继承自lable结构,这是构造函数的写法
下面的也是
[/Quote]
或者label是ME_Sample的一个成员,用构造函数将其初始化
昵称很不好取 2010-03-13
  • 打赏
  • 举报
回复
ME_Sample() :label("") {}; ———— ME_Sample结构继承自lable结构,这是构造函数的写法
下面的也是

64,683

社区成员

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

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