2019-05-05 21:01:16 +02:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
template <typename type>
|
|
|
|
class Array {
|
|
|
|
private:
|
2019-05-13 20:54:13 +02:00
|
|
|
type* basePtr;
|
|
|
|
Array(unsigned int n){
|
|
|
|
basePtr=(type*)malloc(sizeof(type)*n); //allocate the memory
|
|
|
|
}
|
|
|
|
~Array(){
|
|
|
|
free(basePtr);
|
|
|
|
}
|
2019-05-05 21:01:16 +02:00
|
|
|
public:
|
2019-05-13 20:54:13 +02:00
|
|
|
Array& operator new [](unsigned int n){
|
|
|
|
Array(n);
|
2019-05-05 21:01:16 +02:00
|
|
|
return *this;
|
|
|
|
}
|
2019-05-13 20:54:13 +02:00
|
|
|
void* operator delete [](unsigned int n){
|
2019-05-05 21:01:16 +02:00
|
|
|
~Array();
|
|
|
|
}
|
2019-05-13 20:54:13 +02:00
|
|
|
type operator[](){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
};
|