Hi. I found the problem and as you said, the problem was elsewhere; marked in the following code.
Code:
template <typename T, std::size_t NDimensions>
class Vector
{
public:
typedef T value_type;
typedef std::size_t size_type;
enum { dimensions = NDimensions };
Vector(std::initializer_list<value_type> list)
{
init();
size_type ix = 0;
for (typename std::initializer_list<value_type>::iterator it = list.begin();
it != list.end(); ++it, ++ix)
{
_values[ix] = *it;
}
}
Vector(const Vector &rhs)
{
init();
for (size_type i = 0; i < dimensions; ++i)
{
_values[i] = rhs._values[i];
}
}
Vector()
{
init();
// Problem was Here:
memset(_values, 0, sizeof(_values) * sizeof(*_values));
// Changed it to
// -- memset(_values, 0, dimensions * sizeof(value_type));
}
~Vector()
{
//delete _values;
}
Vector &operator=(const Vector &rhs)
{
for (size_type i = 0; i < dimensions; ++i)
{
_values[i] = rhs._values[i];
}
return *this;
}
value_type &operator[](size_type index)
{
return _values[index];
}
const value_type &operator[](size_type index) const
{
return _values[index];
}
private:
void init()
{
//_values = new value_type[dimensions];
}
//value_type *_values;
value_type _values[dimensions];
};
Now it works as a static array, i can see it from the object size. Thanks for all the replies!
I still don't get why memset(_values, 0, sizeof(_values) * sizeof(*_values)); works for a dynamic but not for a fixed-length array thou, but thats not so important.