You cannot create a class from template parameters that are not known at compile time
Well, I know this

That's why I am having such problems. I have one class, say C, that, in the constructor, reads a file and according to this file will aggregate a object, say B, which has an int template parameter and implements the desired behavior for C. This way I can associate the file contents with different specializations of B (B<0>, B<1>, etc). The first problem is that in C I don't know which specialization of B will be stored. The second problem is that the function in B is supposed to get an argument which type is also unknown, therefore needs to be a template function, not allowing the virtualization.
As for adding parameters that are deduced at runtime, that is ok
do that dispatch first , then do the class dispatch (via hold).
In that case put the parameters into hold. OR do class then the dispatch on runtime, boost::any is a quick way to impliment that.
I am not sure I understood this part. In the meanwhile I have a (ugly) solution already, using boost::any you mencioned. I found a way to propagate the argument's type untill the constructor of C where I can build the B specializations passing the argument type, which will then be used in boost::any_cast<ArgType>. The current code model is this:
#include <iostream>
#include "boost/any.hpp"
using namespace std;
class SomeClass;
struct OtherClass{
int i;
double d;
OtherClass(int ii, double dd):i(ii),d(dd){};
};
struct Base{
virtual double call(boost::any in)=0;
};
template<int L, bool M, class S, class T>
struct B : Base{
double call(boost::any in ){ cout << "Inside B" << endl; return 0;};
};
template<class S,class T>
struct B<0, true, S,T>:Base{
double call(boost::any in){ cout << "Inside B<0,true> and obj.i is "<< boost::any_cast<T*>(in)->i<< endl; return 0;};
};
template<class Q>
class C{
Base* i;
public:
template< class T >
C( T* t ){
i = new B< 0, true, SomeClass, T>();
};
template<class T>
void go( T* t ){
i->call( boost::any(t) );
}
};
int main(void){
typedef C<SomeClass> CS;
CS* c = new CS(new OtherClass(2,1));//dummy object
c->go(new OtherClass(0,2));
return 0;
};
Related to propagation of the argument type: for this I am using a templatized constructor in C and a dummy argument to deduce the type. I have enough information to do this like in a regular function: C<ArgType>(). Is there a way to do something like this or to avoid having to propagate the arg type untill de B objects?
Thank you