Problems with my custom "Array" class

Hello!

I am currently working on a custom "Array" class for a project, and I have run into an error I don't quite understand the source of.

The relevant code is as follows:
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
34
35
36
37
38
39
40
41
42
43
template<typename T> class Array
{
private:
	T errValCopy;

public:
	T __errVal__;
	uint16 __size__;
	T* __ptr__;

	Array(const T& errorValue);
	Array(const Array<T>& other);
	~Array();
};

template<typename T> Array<T>::Array(const T& errorValue):
__ptr__(new T[1]), __size__(0), __errVal__(errorValue) { }

template<typename T> Array<T>::Array(const Array<T>& other)
{
	if (other.__size__ > 0)
	{
		__size__ = other.__size__;
		ptr = new T[__size__];

		for (uint16 i = 0; i < __size__; i++)
		{ __ptr__[i] = other.__ptr__[i]; }
	}

	else
	{
		size = 0;
		ptr = new T[1];
	}

	__errVal__ = other.__errVal__;
}

template<typename T> Array<T>::~Array()
{
	if (__ptr__ != 0)
	{ __ptr__ = 0; delete[] __ptr__; }
}


Wwhen I try to run the following code:
Array<Array<int>> a(Array<int>(-1));
The error log tells me there is no appropriate default constructor available.
If I understand it correctly, "default constructor" refers to the constructor which lets you just write Array<int> a; instead of Array<int> a(...);, but I can't see where in the code such a situation occurs...

I'd appreciate any help I can get with this problem as well.
The problem is on line 4: the constructor of errValCopy is not explicitely called hence a default constructor is required (for Array<int>)

if the template type is int errValCopy remains uninitialized and contains garbage value.
Ah, I see now! Thank you for the help.
Topic archived. No new replies allowed.