i'm working on a array header from base definition of an array to create an array of any type with this header,so i created a array class with functions and constructors. this is my code so far:
#include <iostream>
#define newline "\n"
class Arr
{
public:
typedef float T;
public:
Arr(int size);
Arr(int size, T fill);
T get(unsigned index) const;
void set(unsigned index, T newvalue);
unsigned Size() const;
unsigned SIZE;
void Print();
T* pointer;
private:
};
Arr::Arr(int size,T fill)
{
SIZE = size;
pointer= new T;
for (int i = 0; i < size; i++)
{
*(pointer + i) = fill;
}
}
void Arr::set(unsigned index, T newvalue)
{
for (unsigned i = 0; i < index; i++)
{
pointer++;
}
*pointer = newvalue;
}
void Arr::Print()
{
for (unsigned i = 0; i < SIZE; i++)
{
std::cout << *(pointer+i) << newline;
}
}
at this point,i can see the numbers in array but the program crashes immediatly,so what's the problem?!
thanks...!