我的代码是使用头文件和.cxx文件构建的。在标题中有类的方法的声明,如下所示:
virtual EL::StatusCode setupJob (EL::Job& job);
virtual EL::StatusCode fileExecute ();
virtual EL::StatusCode histInitialize ();
virtual EL::StatusCode changeInput (bool firstFile);
std::vector<TH1F*>* CreateHisto (const char* name, const char* title, int nbin, double xmin, double xmax);
virtual EL::StatusCode initialize ();
virtual EL::StatusCode llselection();
virtual EL::StatusCode execute ();
virtual EL::StatusCode postExecute ();
virtual EL::StatusCode finalize ();
virtual EL::StatusCode histFinalize ();
在.cxx中定义了函数“CreateHisto”:
std::vector<TH1F*>* MyxAODAnalysis :: CreateHisto(const char* name, const char* title, int nbin, double xmin, double xmax)
{
std::vector<TH1F*>* histo = new std::vector<TH1F*>(m_variations.size());
innermap::const_iterator inner_itmap;
mainmap::const_iterator itmap;
for ( itmap = m_variations.begin(); itmap != m_variations.end(); itmap++) {
for (inner_itmap = (*itmap).second.begin(); inner_itmap != (*itmap).second.end(); inner_itmap++) {
int index = (*inner_itmap).second;
std::string nameh = name + ' ' + (*inner_itmap).first;
const char* namehc = nameh.c_str();
histo[index].push_back(new TH1F(namehc, title, nbin, xmin, xmax));
}
}
return histo;
}
在CreateHisto之后我有一个名为initialize()的函数,我必须将名为“m_myhisto”的数据成员初始化为CreateHisto函数,我正在做的是以下内容:
EL::StatusCode MyxAODAnalysis :: initialize ()
{
m_myhisto = MyxAODAnalysis::CreateHisto(name, title, nbin, xmin, xmax);
return EL::StatusCode::SUCCESS;
}
但是这样它不能编译,它给了我以下错误:
error: ‘name’ was not declared in this scope
m_myhisto = MyxAODAnalysis::CreateHisto(name, title, nbin, xmin, xmax);
等功能的其他参数。 为什么他不认识他们,因为他们在标题中被宣布?
答案 0 :(得分:2)
int sum(int x, int y){ return x+y;}
void doSomething()
{
sum(x,y);
}
没有工作
这个例子工作:
int sum(int x, int y){ return x+y;}
void doSomething()
{
int a = 5;
int b = 6;
sum(a,b);
}
x和y是函数的参数 a和b是传递给函数调用的数据。