Passing functor by parameter


Hey guys I have been trying to figure out a problem to find the maximum and minimum value of a list of vertices. To do this I wanted to inject a functor which will compare values. The code should make more sense:

ModelPositioning.cpp ->

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

struct FindMaxX
{
	bool operator() (std::vector<glm::vec3>::const_iterator &it, glm::vec3 &v)
	{
		return	it->x > v.x;
		
	}
};

	 glm::mat4 ModelPositioning::CenterModel(std::vector<glm::vec3> vertices)
	{

		glm::vec3 MaxValue = Find(vertices, FindMax);

		std::cout << MaxValue.x << "  " << MaxValue.y << "  " << MaxValue.z << "  ";

		//FindMin(vertices);
		return glm::mat4(1.0);
	}

	 template <class CompareFunction >
	  glm::vec3 ModelPositioning::Find(const std::vector<glm::vec3> & vertices, const CompareFunction & a)
	 {
		 std::vector<glm::vec3>::const_iterator it;

		 glm::vec3 MaxValue;

		 MaxValue = vertices.at(0);

		 for (it = vertices.begin(); it < vertices.end(); it++)
		 {

			 if (a(it, MaxValue))
			 {
				 MaxValue = *it;
			 }
			
		 return MaxValue;
	 }


ModelPositioning.h ->

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

class ModelPositioning
{
public:
	static glm::mat4 CenterModel(std::vector<glm::vec3> vertices);

private:

	static glm::vec3 FindMax(const std::vector<glm::vec3> vertices);
	template <class CompareFunction>
	static glm::vec3 Find(const std::vector<glm::vec3> & vertices, const CompareFunction & a);


};



When I try and run I get a linker error :
LNK2019: unresolved external symbol "private: static struct glm::tvec3<float,0> __cdecl ModelPositioning::FindMax(class std::vector<struct glm::tvec3<float,0>,class std::allocator<struct glm::tvec3<float,0> > >)

Any Ideas??
@ne555 I tried putting the whole function in the header file, it still gives me the same error.
Line 9 in ModelPositioning.h declares a static member function called FindMax. That function isn't defined in ModelPositioning.cpp. Instead you have a global functor called FindMax defined there.
@dhayden Alright, sorry templates and functors are new topics for me so I thought I was not understanding something and focusing on them. Thank you for your reply.
Topic archived. No new replies allowed.