我的代码中有这个奇怪的错误,我似乎无法弄清楚发生了什么。这里有比我更知识渊博的人,所以我想我会发布这个问题。
此代码正常运行:
histogram_requests -> AddHistos("trajTree",
{
.fill = "HitEfficiency_vs_Layers",
.pfs = {},
.cuts = {},
.draw = "LPE1",
.opt = "",
.ranges = {0.0, 0.0}
});
AddHistos的声明如下:
void AddHistos(std::string name, HistoParams hp, bool AddCutsToTitle = true);
HistoParams是一个结构:
typedef struct HistoParams
{
std::string fill;
std::vector<const char*> pfs;
std::vector<const char*> cuts;
std::string draw;
std::string opt;
std::vector<double> ranges;
} HistoParams;
因此根据定义,.cuts的类型应该是const char *的std :: vector。但每当我尝试做这样的事情时:
std::vector<const char*> added_cuts = {};
if(options.add_cuts)
{
added_cuts.push_back("EffCuts");
}
histogram_requests -> AddHistos("trajTree",
{
.fill = "HitEfficiency_vs_Layers",
.pfs = {},
.cuts = added_cuts,
.draw = "LPE1",
.opt = "",
.ranges = {0.0, 0.0}
});
然后我收到以下错误:
错误:没有匹配函数来调用'Custom_smart_histos :: AddHistos(const char [9],大括号括起初始化列表)'
有人可以告诉我为什么会收到此错误,或者如何正确执行此操作? 非常感谢!
答案 0 :(得分:0)
我弄清楚问题是什么,对不起这个问题的含糊不清。 我知道的Histoparams的实现是旧的。由于我所包含的标题被保护,我甚至没有注意到它被覆盖了。新的定义切割为std :: vector。切换到那就解决了问题。