#ifndef findHPP #define findHPP #include struct Point { private: int m_x; int m_y; public: Point() : m_x(0), m_y(0) {} Point(int x) : m_x(x), m_y(0) {} Point(int x, int y) : m_x(x), m_y(y) {} int x() const { return m_x; } int y() const { return m_y; } bool operator == (const Point& anotherPoint) const { return m_x == anotherPoint.m_x && m_y == anotherPoint.m_y; } }; template int find(const T* theArray, int theArrayLength, T theValue) { for (int index = 0; index < theArrayLength; index++) { if (theArray[index] == theValue) return index; } return -1; } void test() { int arrayOfIntegers[8] = { 2, 4, 3, 7, 1, 8, 9, 5 }; float arrayOfFloats[6] = { 1.3, 3.4, 2.3, 4.7, 1.9, 7.2 }; Point arrayOfPoints[4] = { Point(2,3), Point(4,5), Point(0,0), Point(7, 8) }; std::cout << "Position of 3:" << find(arrayOfIntegers, 8, 3) << "\n"; std::cout << "Position of 4.7:" << find(arrayOfFloats, 6, (float)4.7) << "\n"; std::cout << "Position of {0, 0}:" << find(arrayOfPoints, 4, Point(0, 0)) << "\n"; } #endif