It looks like you want to decide at run-time which class to create, i.e.
you want you decide at run-time which code to run. Alas, templates are a
compile-time feature, so it is impossible to use them in such a way
(with templates you need to know already at compile time which code you
want to run).
Not exactly sure what you want to achieve. One approach would be to
derive c_idasection and c_IDALabel from a common base class with virtual
interface. The function which does the runtime dispatch is an ordinary
function, not a template:
base* Register_New(std::string vName, int vType){
if(vType == 1) {
return new c_idasection(this, vName, 1);
} else if (vType == 3) {
return new c_IDALabel(this, vName, 1);
}
return NULL;
}
base* obj = Register_New("blabla", 1);
obj->SomeVirtualFunction();
Of course, using raw pointers is error prone, suggesting to use some
sort of smartpointers like std::unique_ptr or std::shared_ptr instead.
Another possibility is that you want to process things by some common
template function. In this case you still need non-template dispatch
function, which forwards to templates:
template<class T>
void Process(std::string vName) {
T obj(this, vName, 1);
obj.DoSomething();
// call some other templates, etc.
}
void Dispatch(std::string vName, int vType){
if(vType == 1) {
Process<c_idasection>(vName);
} else if (vType == 3) {
Process<c_IDALabel>(vName);
}
}
In this approach, there is no common base class or virtual functions
needed, but for example keeping the objects around for a later use would
be more cumbersome.
HTH
Paavo