The code basically checks the given array is symmetrical or not. When i send parameter std::array i get this error :
ccCPLdU9.o:main.cpp:(.text+0x5da): undefined reference to
bool isItSymmetrical<5u>(std::array<int, >5u> const&)' AppData\Local\Temp\ccCPLdU9.o:main.cpp:(.text+0x60b): undefined reference to >
bool isItSymmetrical<2u>(std::array const&)'
std::array implementation should be work with unknown size, i couldn't figure out why it turned out. the error
Other implementations works well by the way.
My question5.hpp file
#ifndef question5_hpp
#define question5_hpp
#include <iostream>
#include <array>
#include <vector>
bool isItSymmetrical(int const arr[], int size);
template<std::size_t SIZE>
bool isItSymmetrical(const std::array<int, SIZE> &arr);
bool isItSymmetrical(const std::vector<int> v);
#endif /* question5_hpp */
Related question5.cpp file
template<std::size_t SIZE>
bool isItSymmetrical(const std::array<int, SIZE> &arr)
{
for (int i = 0; i < (int)(arr.size()/2); i++)
{
if (arr[i] != arr[arr.size()-i-1])
{
return false;
}
}
return true;
}
And main.cpp
std::array<int,5> ar1 {2, 4, 6, 8, 10};
std::array<int,5> ar2 {2,4,5,4,2};
std::array<int,2> ar3 {1,2};
std::cout << isItSymmetrical(ar1) << "\n";
std::cout << isItSymmetrical(ar2) << "\n";
std::cout << isItSymmetrical(ar3) << "\n";