0

I am trying to use the for_each from stl algorithm.
http://www.cplusplus.com/reference/algorithm/for_each.html

#include <algorithm>
#include <vector>
#include <iostream>

	template <typename T>
	void OutputObject(const T &obj)
	{
		cout << obj << endl;
	}
	
	template <typename T>
	void OutputVector(const vector<T> &V)
	{
		for_each (V.begin(), V.end(), OutputObject);
		cout << endl;
	}

I get "no matching function call to for_each". Why would that be?

Thanks,
Dave

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by daviddoria
0

You need to instantiate the OutputObject template: for_each (V.begin(), V.end(), OutputObject<T>);

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.