template <typename T>
class A
{
public:
T t;
void Do (void)
{
t.doSomething();
}
};
In the above, how do I supply parameters to the constructor of 't' at the time of template instantiation?.
Like, if I had:
class P1
{
public:
P1 (int i, int a) {}
};
class P2
{
public:
P2 (int a) {}
};
I would like to use both P1 and P2 as template parameters to A.. Currently i'm supplying an instance of P1/P2 to the ctor of A, from where 't' is initialized using a copy-ctor.
The bigger picture (For UncleBens, GMan):
I have a whole lot of data-structures (DS) with a lot of fiends in it. Each of these DS is stored in a Database, shown in the ui and transacted over RPC. I have a class to validate each of these DS. The validation class should be behave differently based on the situation where it is validating. When validation of data fetched from the DB fails, it should log a 'developer understandable' error and die with an assertion. When validation of data got from an rpc-client fails, the server should respond an appropriate error. When validation of data got from an rpc-server fails, it should be logged and the client should crash. When validation fails on the UI, the user should be notified.
I decided to make the 'error-handling' a policy that can be chosen at compile time as a template parameter. However, each of these error-handling mechanism require different ways of construction. And, thats where I'm stuck.
As of now, I have a copy constructor based mechanism where I am mentioning the type twice (once as a parameter to the template, and again as in instance to the ctor of the instantiation), which is redundant.
I want to know how other people would solve such a case.