Cint: Generate dictionary for class template with function template

Hello everybody,

I am trying to use a class template with a function template in RootCint, and while I can instantiate the class, the function is not being recognized. I am not sure if the problem lies with the LinkDef.h file, or if I am making some other mistake (Root-newbie here), however, rootcint doesn’t complain when generating the dictionary. (I am developing on Visual Studio 2013, with Root 5.34)

The class looks like this:
// flow.h
template<class Value, class Date>
class Flow : public TObject {
public:
Flow() {}
~Flow(){}
template<class DateIterator, class ValueIterator>
bool AddFlow(FlowType flowType, DateIterator dBegin, DateIterator dEnd, ValueIterator vBegin) {

}
ClassDef(Flow, 1);
};

//flow.cpp
#include “flow.h”

templateClassImp(Flow);

And the LinkDef.h file:

#ifndef LINKDEF_H_
#define LINKDEF_H_
#ifdef CINT
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ nestedclasses;
#pragma link C++ defined_in “date.h”;
#pragma link C++ enum FlowType;
#pragma link C++ class Flow<double, Date>+;
#pragma link C++ operators std::vector::iterator;
#pragma link C++ operators std::vector::iterator;
#pragma link C++ function Flow<double, Date>::AddFlow(FlowType, std::vector::iterator, std::vector::iterator>, std::vector::iterator);
#endif
#endif

Instantiation in RootCint works like this:

gSystem->Load(“test.dll”);
std::vector dates;
std::vector values;
dates.push_back(TDate(1,1,2015));
dates.push_back(TDate(2,1,2015));
dates.push_back(TDate(3,1,2015));
values.push_back(1.0);
values.push_back(1.1);
values.push_back(1.2);
Flow<double, Date> flow;
flow.AddFlow(FlowType::cashed, dates.begin(), dates.end(), values.begin());

And here I get the error: Can’t call Flow<double, Date>::AddPattern(…) in current scope…,
with no other function-suggestions from Cint.

I guess the fault lies within the dictionary generation, but I am all out of ideas here.

Cheers, Simon

I managed to solve it myself, by hiding the implementation of the method from root(cint), as found in another post.

Now there is just the declaration of the method in the class template body, while the implementation is done outside of the class, surrounded by
#if !defined(CINT)
#endif

Actually I do not understand why you need to have a template method at all. Would the following work for yu?

template<class Value, class Date>
class Flow : public TObject {
public:
typedef std::vector<Value>::iterator ValueIterator;
typedef std::vector<Date>::iterator DateIterator;

Flow() {}
~Flow(){}
bool AddFlow(FlowType flowType, DateIterator dBegin, DateIterator dEnd, ValueIterator vBegin) {
...
}

Very good point, thank you!
In this case I just followed the implementation in another class template (timeseries from QuantLib), which is a member of the flow class. I guess their intention was to keep the flexibility, and allow for arbitrary container classes with different iterators.