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

Recommended Answers

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

Jump to Post

All 2 Replies

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

ah cool. thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.