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
| template <class T, std::size_t N> class CMyArray
{
public:
T m_array[N];
static const unsigned int m_static_size = N;
// functions
inline std::size_t size() const { return m_static_size; }
inline const T* data() const { return m_array; }
inline void assign(const T * _array)
{ memcpy((*this).m_array, _array, sizeof(T)*N); }
// operators
T& operator[](int);
T operator[](int) const;
template<class U> CMyArray& operator=(const CMyArray<U, N>& a)
{
memcpy((*this).m_array, a.m_array, sizeof(U)*N);
return (*this);
}
int operator==(const CMyArray<T, N>&) const;
int operator!=(const CMyArray<T, N>&) const;
// friends
template<class T2, std::size_t N2> friend std::ostream& operator<<( std::ostream&, const CMyArray<T2, N2>&);
};
// main de test
int main()
{
CMyArray<int, 4> var = {0, 1, 2, 3};
return 0;
} |
Partager