提问人:Kevin 提问时间:10/5/2023 最后编辑:mchKevin 更新时间:10/5/2023 访问量:57
c++ 14 3 个字符串的分类列表
c++ 14 Categorized List of 3 Strings
问:
今天早上我的大脑被炸了,我正在努力理解为什么我会遇到编译器错误。
error: no matching constructor for initialization of 'list<data::tweak_cat>'
我的代码是这样的:
#include <list>
#include <string>
// fire up our std namespace
using namespace std;
namespace data {
// create a structure to hold the tweak data
struct the_tweak {
string _name;
string _value;
string _type;
};
// create a structure to hold our category data
struct tweak_cat {
string _category;
list< the_tweak > data;
};
class properties {
public:
// return our lists of strings for the tweak properties
static list< tweak_cat > tweak_properties( ) {
// hold the return
list< tweak_cat > _ret = {
{ "debugging",
{ "testing", "0", "" },
},
{ "dozing",
{ "testing2", "this", "" },
{ "testing3", "that", "" },
{ "testing4", "0", "theother" },
},
};
// return it
return _ret;
}
};
}
我正在为我的手机构建一组基于cli的调整,在这个过程中,我试图自学一些c++并对其进行编译。我哪里出了问题,我该如何纠正?
我的理解(来自阅读)列表是在向量和数组上“存储”此类数据的更有效方法......我最初没有类别父级,它工作正常......vector< vector< string > >
答:
4赞
kiner_shah
10/5/2023
#1
您需要添加更多大括号,因为结构为:
tweak_cat
{
string,
list
{
the_tweak { name, value, type },
the_tweak { name, value, type },
the_tweak { name, value, type },
}
}
法典:
list<tweak_cat> _ret = {
{
"debugging",
{
{"testing", "0", ""}
}
},
{
"dozing",
{
{"testing2", "this", ""},
{"testing3", "that", ""},
{"testing4", "0", "theother"}
}
},
};
以上应该编译。
评论
1赞
Kevin
10/5/2023
谢谢你提供额外的脑细胞。这确实做到了。:)
下一个:C++ 迭代器引用不存在的值
评论
{
}
tweak_cat::data
using namespace std;