I was trying yo create my own array class (similar to std::vector) just for fun but there is some problem... The Array class code itself works and compiles successfully but throws an error if i try to instantiate an object of Array class.
#include<iostream>
template<typename type, int size>
class Array
{
private:
type _mArray[size] = new type[size];
public:
int Access(int index)
{
return _mArray[index];
}
int Len()
{
return size;
}
void Insert(int index, type val)
{
_mArray[index] = val;
}
~Array()
{
delete[] _mArray;
}
};//All code above compiles successfully
int main()
{
Array<int, 2> name; //this line throws an error
}
I am a bit new to C++ so if someone can explain then I will be very thankful....
Btw here is the error Array initializer must be an initializer list
int main() { Array<int, 2> name; Array<int, 2> name2; name = name2; }-- Double deletion error at runtime. You still have work today to get this code to actually be useful.std::array(fixed size array) thanstd::vector(dynamic size array).