What is wrong with this code
and how do I fix?
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<typename T>
class Array
{
public:
Array(unsigned arraySize):
data(0), size(arraySize)
{
if (size > 0)
data = new T[size0;
}
~Array()
{
if (data) delete[] data;
}
void setValue(unsigned index, const T& value)
{
if (index < size)
data[index] = value;
}
T getValue(unsigned index) const
{
if (index < size)
return data[index];
else
return T();
}
private: T* data;
unsigned size;
};
|
Correction due to typo:
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<typename T>
class Array
{
public:
Array(unsigned arraySize):
data(0), size(arraySize)
{
if (size > 0)
data = new T[size);
}
~Array()
{
if (data) delete[] data;
}
void setValue(unsigned index, const T& value)
{
if (index < size)
data[index] = value;
}
T getValue(unsigned index) const
{
if (index < size)
return data[index];
else
return T();
}
private: T* data;
unsigned size;
};
|
Topic archived. No new replies allowed.