#include <algorithm>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <ostream>
#include <vector>
template <typename T>
class Vector: public std::vector<T> {
public:
Vector(std::initializer_list<T> il):
std::vector<T>(il)
{
}
typename std::vector<T>::size_type length() const
{
return std::vector<T>::size();
}
void sort()
{
std::sort(std::vector<T>::begin(), std::vector<T>::end());
}
void printOn(std::ostream &os = std::cout) const
{
for (const T &t: *this)
os << t << ' ';
os << std::endl;
}
};
int main()
{
Vector<int> vi{4, -4, 6, -5, 200, 90};
vi.printOn();
vi.sort();
vi.printOn();
}
Hmm. How long can you go on like this, until you start relying on the internal implementation? Look at how ugly the code looks, too. (Unless there's something I don't know.)
And finally: is your own Vector compatible with std::vector? Not unless you write an conversion constructor or a conversion operator.