For example, if I have a vector
in a template class, than how can I sort it, or how can I iterate on the vector? Because I tried like this:
#ifndef SAVEVIEW_H
#include <array>
#include <vector>
template<typename T>
class sorted_array_view {
public:
sorted_array_view(T* array, size_t size) {
append(array, size);
}
void append(T* array, size_t size) {
for( int idx = 0; idx < size; ++idx)
{
std::cout << "value of array at " << idx <<": "<< array[idx] << std::endl;
data.push_back(array[idx]);
}
sort(first(),last(), data);
}
T at(size_t index) const {
return data[index];
}
size_t size() {
return data.size();
}
const size_t size() const {
return data.size();
}
private:
size_t first() {
return data[0];
}
size_t last() {
return data[data.size()-1];
}
void sort (sorted_array_view first, sorted_array_view last, std::vector<T>);
std::vector<T> data;
};
#endif // SAVEVIEW_H
And use with:
sort(first(),last(), data);
returned me this error:
error: no matching function for call to 'sorted_array_view<int>::sort(size_t, size_t, std::vector<int, std::allocator<int> >&)'
Any idea, advice? Thank you!