Difficulty building dictionaries for template classes

Hello,

I am trying to make a class which will be used to handle data which will be read from a TTree and then used to fill histograms. Since histograms can store Int_t, Float_t and Double_t, I am trying to use templates. However, I am experiencing problems when building the dictionary.

So here is my class

[code]template
class NtupleObservable {
T m_value;
std::vector m_bins;
int m_nBins;
std::string m_branchName;
TBranch * m_branch;

public:
NtupleObservable(const std::string &branchName, const std::vector &bins)
: m_value(-999), m_bins(bins), m_nBins(bins.size())
, m_branchName(branchName), m_branch(NULL)
{ }

void Init (TTree * tree) {
  Error("Init", "Unsupported branch type");
}

};

template <>
void NtupleObservable<Int_t>::Init (TTree * tree) {
tree->SetBranchAddress(m_branchName.c_str(), &m_value, &m_branch, NULL, kInt_t, 0);
}

template <>
void NtupleObservable<Float_t>::Init (TTree * tree) {
tree->SetBranchAddress(m_branchName.c_str(), &m_value, &m_branch, NULL, kFloat_t, 0);
}

template <>
void NtupleObservable<Double_t>::Init (TTree * tree) {
tree->SetBranchAddress(m_branchName.c_str(), &m_value, &m_branch, NULL, kDouble_t, 0);
}[/code]

and then the LinkDef.h

#include "NtupleObservable.h"

#ifdef __CINT__

#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ nestedclass;

#pragma link C++ class NtupleObservable<Float_t>+;

#endif

I’m using the class like "NtupleObservable<Float_t> in a separate file, etc. and during the build I get errors complaining
no matching function for call to ‘NtupleObservable::NtupleObservable()’
…/HWWUnfoldingCode/NtupleObservable.h:19: note: candidates are: NtupleObservable::NtupleObservable(const std::string&, const std::vector<T, std::allocator<_CharT> >&) [with T = float]

I find this confusing because I am trying to use <Float_t> and not . Could you please help?

Hi,

To support I/O you need to provide a default constructor (a constructor with no parameter or all parameter which a default value), that is what the error message is complaining about. (Float_t and float are the ‘same’ thing. Float_t is a typedef to float).

Cheers,
Philippe.