passing template class as temporary object

i have a template classa as shown below, i want to call it in for_each method using the temporary object... how can i do this. i have already done this by class variable, but i have to do same by temporary object.. can anybody help thanks

template <class T> class My_action


My_action(T a)
cout << a << endl;
void operator() (T a)
cout << a << endl;

int main()

vector<int> vi(MAX);
vector<double> vd(MAX);
vector<string> vs(MAX); = 2; = 4; = 6; = 8; = 10;

My_action<int> i_action;
for_each(vi.begin(),vi.end(),i_action );

Is this what you mean?
//My_action<int> i_action;

If that doesn't work, try:
Last edited on
Topic archived. No new replies allowed.