Hello all,
Before anything else, this issue is also posted at: http://www.cplusplus.com/forum/general/7518/
I have a structure similar to the one below.I miss a lot of information about the specific template parameters, so I would need something like what is in the code. This code does not compile because we cannot have templatized virtual member functions. Does anyone have a clever idea how to solve this? The result I want is to get through the specialized operator() of B<O,true>.
#include <iostream>
using namespace std;
class SomeClass;
/* In the real code I have SomeClass< T, P, Q>
* and this is not known when the compiler reaches A,B and C*/
struct OtherClass{
int i;
double d;
OtherClass(int ii, double dd):i(ii),d(dd){};
};
/* My idea of A is this, although it is not
* possible to have a virtual template function */
class A{
public:
template<class K>
virtual void operator()(K input )=0;
};
template<int L, bool M, class S>
struct B : public A{
template<class K>
void operator()(K input ){ cout << "Inside B" << endl; };
};
template<class S>
struct B<0, true, S> : public A{
template<class K>
void operator()(K input ){ cout << "Inside B<0,true>"<< endl; };
};
/* This class creates and stores an object of type B (or one of the specializations).
* But L and M are unknown so I created A to store the B object here
* K is also unknown here. */
class C{
A* object;
public:
C(){
/*
* Get some data from files and according
* to this data construct a B specialized object. */
object = new B< 0, true, SomeClass>();
};
void go(){
/*
* Later, I want to call B, that was stored through the interface A
*/
(*object)(new OtherClass(0,2));
}
};
int main(void){
C* c = new C();
c->go();
return 0;
};