c++ Access 2D array of vectors through pointer - c++

I have a class that simulates 2D matrix through the use of nested vectors as follows:
In the class header file this is what I have:
template <typename T> class L1Matrix {
private:
std::vector<std::vector<T> > mat;
unsigned rows;
unsigned cols;
public:
L1Matrix(); /* emptry constructor */
L1Matrix(unsigned _rows, unsigned _cols, const T& _initial);
L1Matrix(const L1Matrix<T>& rhs);
virtual ~L1Matrix();
T& operator()(const unsigned& row, const unsigned& col);
const T& operator()(const unsigned& row, const unsigned& col) const;
}
In the class declaration this is what I have:
// default constructor
template<typename T>
L1Matrix<T>::L1Matrix() : rows(0), cols(0) {};
template<typename T>
L1Matrix<T>::L1Matrix(unsigned _rows, unsigned _cols, const T& _initial) {
mat.resize(_rows);
for (unsigned i=0; i<mat.size(); i++) {
mat[i].resize(_cols, _initial);
}
rows = _rows;
cols = _cols;
}
template<typename T>
L1Matrix<T>::L1Matrix(const L1Matrix<T>& rhs) {
mat = rhs.mat;
rows = rhs.get_rows();
cols = rhs.get_cols();
}
template<typename T>
std::vector<std::vector<T> >::reference L1Matrix<T>::operator()(const unsigned& row, const unsigned& col) {
return this->mat[row][col];
}
For sake of brevity I am not giving the rest of the class implementation here.
Now in the main code I am creating pointer to this 2D matrix as follows:
L1Matrix<bool>* arr1; // this is pointer to L1Matrix object
L1Matrix<int> arr2(XSize, YSize, 0); // L1Mtarix object
arr1 = new L1Matrix<bool>(XSize, YSize, true);
Now for the actual L1Matrix object arr2 I can access the individual rows and columns like this: arr2(row,col) but my question is how to access the similar row and column elements using the L1Matrix pointer object arr1?
Please let me know.
Thanks

You should be able to use (*arr1)(row, col)

Related

Use assignment operator with subscript operator to assign value to std::map

I have a Matrix class
template <typename T>
class Matrix
{
public:
const size_t rows;
const size_t cols;
const std::map<std::array<int, 2>, T> data;
Matrix(int a, int b) : rows(a), cols(b)
{
}
};
which is initialized like this:
Matrix<double> M(5,5);
creating a 5x5 matrix.
I want to assign values to the map like so:
M[{1,2}] = 1;
How would I go about doing that in the most readable way? I'm not sure how to get the subscript and assignment operator working together.
Let's add some helper aliases to Matrix while we are at it
template <typename T>
class Matrix
{
// rather than stoping people changing the members via const
// make them private
size_t rows;
size_t cols;
map_type data;
public:
using key_type = std::array<size_t, 2>;
using mapped_type = T;
using map_type = std::map<key_type, mapped_type>;
Matrix(size_t r, size_t c) : rows(r), cols(c) { }
const T& operator [](key_type key) const { return data[key]; }
T& operator [](key_type key) { return data[key]; }
// other operations as appropriate
};
You have to provide members:
const T& operator [](std::pair<std::size_t, std::size_t>) const;
T& operator [](std::pair<std::size_t, std::size_t>);

C++ Constructor inheritance no matching function

I'm currently working on a project with several classes :
an abstract one : template <typename Elem> class Vector {...}
another abstract one : template <typename Elem> class AbsPolynom: virtual public Vector<Elem>
a inheritence from Vector : template <typename Elem> class Dvector: virtual public Vector<Elem>
and the last one : template <typename Elem> class Polynom: public AbsPolynom<Elem>, public Dvector<Elem>{
When I call Polynom, like this : Polynom<int> test(std::size_t(3),3,3);
I get this error :
In file included from Polynom.cpp:6:0,
from main2.cpp:4:
Polynom.hpp: In instantiation of ‘Polynom::Polynom(std::size_t, const Elem&, const int&) [with Elem = int; std::size_t = long unsigned int]’:
main2.cpp:10:41: required from here
Polynom.hpp:14:105: error: no matching function for call to ‘Vector::Vector()’
Polynom(std::size_t dim, const Elem& value, const int& degrees ): AbsPolynom(dim, value, degrees) {};
So here is my question : Why does it call this constructor from Vector? I always have a parameter but it initializes this class without parameters
Here are my Constructors :
Polynom :
Polynom(std::size_t dim, const Elem& value, const int& degrees ): AbsPolynom<Elem>(dim, value, degrees) {};
Polynom(std::size_t dim, const Elem& value, const int degrees[] ): AbsPolynom<Elem>(dim, value, degrees) {};
Polynom(std::size_t dim, const Elem values[], const int& degrees): AbsPolynom<Elem>(dim, values, degrees) {};
Polynom(std::size_t dim, const Elem values[], const int degrees[]): AbsPolynom<Elem>(dim, values, degrees) {};
AbsPolynom :
explicit AbsPolynom(std::size_t, const Elem&, const int& );
explicit AbsPolynom(std::size_t, const Elem&, const int [] );
explicit AbsPolynom(std::size_t, const Elem [], const int& );
explicit AbsPolynom(std::size_t, const Elem [], const int [] );
template <typename Elem>AbsPolynom<Elem>::AbsPolynom(std::size_t dim, const Elem& value, const int& degrees ): Vector<Elem>(dim, value), _degrees(new Elem[dim]),_polynomDegree(degrees) {
for (std::size_t i = 0; i < dim; ++i) _degrees[i] = degrees;}
template <typename Elem>AbsPolynom<Elem>::AbsPolynom(std::size_t dim, const Elem& value, const int degrees[] ): Vector<Elem>(dim, value), _degrees(new Elem[dim]),_polynomDegree(degrees[0]) {
for (std::size_t i = 0; i < dim; ++i) _degrees[i] = degrees[i];}
template <typename Elem>AbsPolynom<Elem>:: AbsPolynom(std::size_t dim, const Elem values[], const int& degrees): Vector<Elem>(dim, values), _degrees(new Elem[dim]),_polynomDegree(degrees) {
for (std::size_t i = 0; i < dim; ++i) _degrees[i] = degrees;}
template <typename Elem>AbsPolynom<Elem>::AbsPolynom(std::size_t dim, const Elem values[], const int degrees[]): Vector<Elem>(dim, values), _degrees(new Elem[dim]),_polynomDegree(degrees[0]) {
for (std::size_t i = 0; i < dim; ++i) _degrees[i] = degrees[i];}
and Vector :
explicit Vector(std::size_t dim, const Elem& elem);
explicit Vector(std::size_t, const Elem[] );
template <typename Elem>Vector<Elem>::Vector (std::size_t dim, const Elem& elem):_dim(dim), _values(new Elem[dim]) {
for (std::size_t i = 0; i < dim; ++i) _values[i] = elem; }
template <typename Elem>Vector<Elem>::Vector ( std::size_t dim, const Elem elem[]):_dim(dim), _values(new Elem[dim]) {
for (std::size_t i = 0; i < dim; ++i) _values[i] = elem[i];
}
When you have virtual inheritance, the most derived class has to call the constructor for the virtual base class. There is only one copy, and it has to be called exactly once.
If not called, the compiler tries to call the default constructor (and fails if there is none).

Cannot convert from *const to & in += operator [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I was staring at this all night before I decided to give up and go to sleep - a few hours into it again today, I still don't have it. I am unable to figure out how to change the const-ness and parameters to correctly return (on the operator+=). Any help?
The error pops up at the return this statement in the operator+= overload.
#include <iostream>
#include <vector>
template <typename T> class Matrix {
private:
unsigned rows, cols;
public:
Matrix();
~Matrix();
Matrix(const Matrix<T>& rhs);
Matrix(unsigned _rows, unsigned _cols);
std::vector<std::vector<T>> matrix;
Matrix<T>& operator=(Matrix<T> rhs);
//Matrix mathematical operations
Matrix<T> operator+(const Matrix<T>& rhs);
Matrix<T>& operator+=(const Matrix<T>& rhs);
// Access the individual elements
T& operator()(const unsigned& row, const unsigned& col);
const T& operator()(const unsigned& row, const unsigned& col) const;
// Access the row and column sizes
unsigned get_rows() const;
unsigned get_cols() const;
void swap(Matrix<T>& rhs);
};
template<typename T>
Matrix<T>::Matrix() {}
template<typename T>
Matrix<T>::~Matrix() {}
// Parameter Constructor
template<typename T>
Matrix<T>::Matrix(unsigned _rows, unsigned _cols) {
matrix.resize(_rows);
for (unsigned i = 0; i < _rows; i++)
matrix[i].resize(_cols, 1); // change back to 0 after debug
rows = _rows;
cols = _cols;
}
template<typename T>
Matrix<T>& Matrix<T>::operator=(Matrix<T> rhs) {
swap(rhs);
return *this;
}
template<typename T>
Matrix<T> Matrix<T>::operator+(const Matrix<T>& rhs) {
Matrix<T> result(*this);
result += rhs;
return result;
}
template<typename T>
Matrix<T>& Matrix<T>::operator+=(const Matrix<T>& rhs) {
for (unsigned i = 0; i < rows; i++) {
for (unsigned j = 0; j < cols; j++) {
this->matrix[i][j] += rhs(i, j);
}
}
return this; // error pops up here
}
// Access the individual elements
template<typename T>
T& Matrix<T>::operator()(const unsigned& row, const unsigned& col) {
return this->matrix[row][col];
}
// Access the individual elements (const)
template<typename T>
const T& Matrix<T>::operator()(const unsigned& row, const unsigned& col) const{
return this->matrix[row][col];
}
// Get the number of rows of the matrix
template<typename T>
unsigned Matrix<T>::get_rows() const {
return this->rows;
}
//Get the number of columns of the matrix
template<typename T>
unsigned Matrix<T>::get_cols() const {
return this->cols;
}
template<typename T>
void Matrix<T>::swap(Matrix<T>& rhs) {
using std::swap;
swap(this->rows, rhs.rows);
swap(this->cols, rhs.cols);
swap(this->matrix, rhs.matrix);
}
// for debugging
template<typename T>
void print_matrix(Matrix<T>& matrix) {
for (int i = 0; i < matrix.get_rows(); i++) {
for (int j = 0; j < matrix.get_cols(); j++) {
std::cout << matrix(i, j) << " ";
}
std::cout << " " << std::endl;
}
}
int main(int argc, char **argv) {
Matrix<double> matrix1(5, 5);
Matrix<double> matrix2(5, 5);
// Start testing
Matrix<double> matrix3 = matrix1 + matrix2;
print_matrix(matrix1);
std::getchar();
return 0;
}
In the += operator, you probably want:
Matrix<T>& Matrix<T>::operator+=(const Matrix<T>& rhs) {
//....
return *this;
//^^
}
The linker error is because you did not define:
Matrix(const Matrix<T>& rhs);

Overloading templated class binary operator*

I'm writing a 2D matrix template to learn templates and some C++11 features.
Wrote the following header:
template <class T, unsigned int Rows, unsigned int Columns>
class Matrix2D
{
private:
array<array<T,Columns>, Rows> m_Matrix;
public:
Matrix2D() {}
array<T,Columns>& operator[](unsigned int row) { return m_Matrix[row]; } ;
const array<T,Columns>& operator[](unsigned int row) const { return m_Matrix[row]; } ;
friend Matrix2D operator+ <> (const Matrix2D &lhs, const Matrix2D &rhs);
friend Matrix2D operator* <> (const Matrix2D &lhs, const Matrix2D &rhs);
};
The operator+ works fine - I have an implementation, it compiles, links, and stepped through with the debugger.
Problem is with operator*, for which I get the compilation error
1>...\matrix2d.h(18): error C2143: syntax error : missing ';' before '<'
1>...\matrix2d.h(19) : see reference to class template instantiation 'Matrix2D<T,Rows,Columns>' being compiled
There's no line of code trying to use the operator, so it's the definition itself which is wrong, I just don't understand why.
Can anyone help?
EDIT: (added from comment)
template <class T, unsigned int Rows, unsigned int Columns>
Matrix2D<T, Rows, Columns> operator+ (const Matrix2D<T, Rows, Columns> &lhs, const Matrix2D<T, Rows, Columns> &rhs)
{
Matrix2D<T, Rows, Columns> addResult;
for (unsigned int i = 0; i < Rows; i++)
for (unsigned int j = 0; j < Columns; j++)
addResult[i][j] = lhs[i][j] + rhs[i][j];
return addResult;
}
template <class T, unsigned int Rows, unsigned int Columns>
Matrix2D<T, Rows, Columns> operator* (const Matrix2D<T, lRows, lColumns> &lhs, const Matrix2D<T, rRows, rColumns> &rhs)
{
Matrix2D<T, lRows, rColumns> mulResult;
for(unsigned int i = 0; i < lRows; i++)
for(unsigned int j = 0; j < rColumns; j++)
for (unsigned int k = 0; k < lColumns; k++)
mulResult[i][k] += lhs[i][k] * rhs[k][j];
return addResult;
}
You cannot friend a specialization of an undeclared template function. Of course, declaring the operators before defining the class template will require you to forward declare it as well:
template <class T, unsigned int Rows, unsigned int Columns>
class Matrix2D;
template <class T, unsigned int Rows, unsigned int Columns>
Matrix2D<T, Rows, Columns>
operator+ (const Matrix2D<T, Rows, Columns> &lhs, const Matrix2D<T, Rows, Columns> &rhs);
template <class T, unsigned int Rows, unsigned int Columns>
Matrix2D<T, Rows, Columns>
operator* (const Matrix2D<T, Rows, Columns> &lhs, const Matrix2D<T, Rows, Columns> &rhs);
template <class T, unsigned int Rows, unsigned int Columns>
class Matrix2D
{
private:
array<array<T,Columns>, Rows> m_Matrix;
public:
Matrix2D() {}
array<T,Columns>& operator[](unsigned int row) { return m_Matrix[row]; }
const array<T,Columns>& operator[](unsigned int row) const { return m_Matrix[row]; }
friend Matrix2D operator+ <> (const Matrix2D &lhs, const Matrix2D &rhs);
friend Matrix2D operator* <> (const Matrix2D &lhs, const Matrix2D &rhs);
};
alternatively, you could take the easy way and define separate operator functions for each specialization of Matrix2D:
template <class T, unsigned int Rows, unsigned int Columns>
class Matrix2D
{
private:
array<array<T,Columns>, Rows> m_Matrix;
public:
Matrix2D() {}
array<T,Columns>& operator[](unsigned int row) { return m_Matrix[row]; }
const array<T,Columns>& operator[](unsigned int row) const { return m_Matrix[row]; }
friend Matrix2D operator+ (const Matrix2D &lhs, const Matrix2D &rhs) {
// do stuff that adds.
}
friend Matrix2D operator* (const Matrix2D &lhs, const Matrix2D &rhs) {
// do stuff that multiplies.
}
};
which I would probably use for the simpler overall syntax.
EDIT: Proper multiplication of non-square matrices means that the operator* function would in fact need to be friends of three different specializations of Matrix2D: the type of the left operand, right operand, and result. I think the first approach herein would become untenable. You should either friend all specializations of operator*:
template <class T, unsigned int Rows, unsigned int Columns>
class Matrix2D
{
// ...
template <typename U, typename V, unsigned Rows, unsigned Common, unsigned Columns>
friend Matrix2D<decltype(std::declval<U>()+std::declval<V>()), Rows, Columns>
operator * (const Matrix2D<U, Rows, Common>&,
const Matrix2D<V, Common, Columns>&);
};
or simply make the data public (probably the best approach for a "collection-of-data" class anyhow).
In:
template <class T, unsigned int Rows, unsigned int Columns>
class Matrix2D
{
// ...
friend Matrix2D operator* <> (const Matrix2D &lhs, const Matrix2D &rhs);
};
Matrix2D refer in fact to Matrix2D<T, Rows, Columns> .
And your operator * should be
template <T, unsigned Rows1, unsigned int Common, unsigned int Column>
Matrix2D<T, Row1, Column> operator* (const Matrix2D<T, Row1, Common>& lhs, const Matrix2D<T, Common, Column>& rhs);

Supporting my_2D_Array[x][y] (double operator[]) on a const 2D array; Cannot get things working

I am creating a 2D array class in C++. Everything works fine for a non-cost array.
I have yet to find a good explanation of const functions, and always seem to fumble around until it works. Now, however, I am at an impass.
Am I not understanding how to support const objects? Short of creating a second Row class, I can't think of a solution, and that solution seems unnecessary.
main.cpp
#include "Array2D.h"
int main()
{
int const x(1), y(1);
Array2D<int> arr(3, 3);
int value(0);
for (int row(0); row < 3; ++row)
for (int column(0); column < 3; ++column)
arr[row][column] = ++value;
std::cout << arr[x][y];
Array2D<int> const carr(arr);
//Everything's fine up to here
std::cout << carr[x][y]; //Error
std::cout << "\n\n[ PAUSE: Press ENTER to exit the program. ]";
std::cin.get();
return 0;
}
When I try to access carr[x][y] it throws an error, which is to be expected. So I included a const and non-const overload of operator[] in Array2D
Array2D.h
template <typename T>
class Array2D
{
public:
//===============
//CONSTRUCTORS
//
inline Array2D();
inline Array2D(int rows, int columns = 0);
inline Array2D(Array2D const &array2D);
//===============
//OPERATORS
//
inline Array2D<T>& operator=(Array2D const &array2D);
inline Row<T> operator[](int index);
inline Row<T> const operator[](int index) const;
//===============
//GETTERS
//
inline int getRows() const { return _rows; }
inline int getColumns() const { return _columns; }
//===============
//SETTERS
//
inline void setRows(int rows); //May result in loss of data
inline void setColumns(int columns); //May result in loss of data
//OTHER
inline T& select(int row, int column);
inline T const & select(int row, int column) const;
//===============
//DESTRUCTOR
//
inline ~Array2D(){}
private:
//===============
//DATA
//
Array<T> _array; //Two dimensional array in row-major order
int _rows; //The number of rows in the array
int _columns; //The number of data in each row
//===============
//PRIVATE FUNCTIONS
//
//Initializes the array with current data
inline void initArray2D();
//Throws exception if length is negative
inline void checkLength(int length) const;
//Throws exception if index is out of bounds
inline void checkIndex(int rowIndex, int columnIndex) const;
};
//CONSTRUCTORS
template <typename T>
Array2D<T>::Array2D() : _array(0), _rows(0), _columns(0)
{ initArray2D(); }
template <typename T>
Array2D<T>::Array2D(int rows, int columns) : _array(0), _rows(rows), _columns(columns)
{
checkLength(rows);
checkLength(columns);
initArray2D();
}
template <typename T>
Array2D<T>::Array2D(Array2D const &array2D)
{ (*this) = array2D; }
//OPERATORS
template <typename T>
Array2D<T>& Array2D<T>::operator=(Array2D const &array2D)
{
_rows = array2D._rows;
_columns = array2D._columns;
initArray2D();
_array = array2D._array;
return *this;
}
template <typename T>
Row<T> Array2D<T>::operator[](int index)
{
return Row<T>(*this, index);
}
template <typename T>
Row<T> const Array2D<T>::operator[](int index) const
{
Row<T> const toReturn(*this, index);;
return toReturn;
}
//SETTERS
template <typename T>
void Array2D<T>::setRows(int rows)
{
_array.setLength(rows * _columns);
}
template <typename T>
void Array2D<T>::setColumns(int columns)
{
Array newArray(_rows * columns);
//This will prevent truncated columns from being copied over
int lesserColumn(columns > _columns ? _columns : columns);
for (int row(0); row < _rows; ++row)
for (int column(0); column < lesserColumn; ++column)
newArray[row][column] = _array[row][column];
_array = newArray;
}
//OTHER
template <typename T>
T& Array2D<T>::select(int row, int column)
{
checkIndex(row, column);
return _array[(row * column) + column];
}
template <typename T>
T const & Array2D<T>::select(int row, int column) const
{
checkIndex(row, column);
return _array[(row * column) + column];
}
// PRIVATE \\
template <typename T>
void Array2D<T>::initArray2D()
{
_array = Array<T>(_rows * _columns);
}
template <typename T>
void Array2D<T>::checkLength(int length) const
{
if (length < 0)
throw Exception("LENGTH_LESS_THAN_ZERO");
}
template <typename T>
void Array2D<T>::checkIndex(int rowIndex, int columnIndex) const
{
if (rowIndex >= _rows || columnIndex >= _columns)
throw Exception("INDEX_LARGER_THAN_UPPER_BOUND");
if (rowIndex < 0 || columnIndex < 0)
throw Exception("INDEX_SMALLER_THAN_LOWER_BOUND");
}
The const functions seem to be in order, however an issue arises when it tries to create the Row object (explained in next paragraph) because it expects an Array2D&, but in the const function it passes a const Array2D&, which naturally does not work.
The idea of the Row object is to pass back something to handle the second [] operator without having to pass back array.
Row.h
template <typename T>
class Array2D;
template <typename T>
class Row
{
public:
//==============
//CONSTRUCTOR
//
inline Row(Array2D<T> &array2D, int row);
//==============
//OPERATORS
//
//The index will be validated by Array2D
inline T& operator[](int column);
inline T const & operator[](int column) const;
private:
//==============
//Data
//
Array2D<T>& _array2D; //Source array
int _row; //The row index
};
template <typename T>
Row<T>::Row(Array2D<T> &array2D, int row) : _array2D(array2D), _row(row)
{ }
template <typename T>
T& Row<T>::operator[](int column)
{
return _array2D.select(_row, column);
}
template <typename T>
T const & Row<T>::operator[](int column) const
{
return _array2D.select(_row, column);
}
Here is Array.h for reference
#pragma once
#include "Exception.h"
template <typename T>
class Array
{
public:
//===============
//CONSTRUCTORS
//
inline Array();
inline Array(int length, int startIndex = 0);
inline Array(Array const &copy);
//===============
//OPERATORS
//
inline Array& operator=(Array const &copy);
inline T& operator[](int index);
inline T const & operator[](int index) const;
//===============
//GETTERS
//
inline int getStartIndex() const { return _startIndex; }
inline int getLength() const { return _length; }
//===============
//SETTERS
//
inline void setStartIndex(int index);
inline void setLength(int length);
//===============
//DECONSTRUCTOR <coolface.jpg>
//
inline ~Array();
private:
//===============
//DATA
//
T* _array; //Pointer to array of type T
int _length; //Length of the array
int _startIndex;
//===============
//PRIVATE FUNCTIONS
//
//Initializes the array with current LENGTH
inline void init();
//Throws exception if length is less than zero
inline void checkLength(int length) const;
//Throws exception if index is out of bounds
inline void checkIndex(int index) const;
//Copies contents of SOURCE to DESTINATION
inline void copyArray(T * destination, T * source, int lastIndex);
};
//CONSTRUCTORS
template <typename T>
Array<T>::Array() : _array(0), _length(0), _startIndex(0)
{ init(); }
template <typename T>
Array<T>::Array(int length, int startIndex = 0) : _array(0), _length(length), _startIndex(startIndex)
{
checkLength(length);
init();
}
template <typename T>
Array<T>::Array(Array const &copy)
{ (*this) = copy; }
//OPERATORS
template <typename T>
Array<T>& Array<T>::operator=(Array const &copy)
{
_length = copy._length;
_startIndex = copy._startIndex;
init();
copyArray(_array, copy._array, _length);
return *this;
}
template <typename T>
T& Array<T>::operator[](int index)
{
checkIndex(index);
return _array[index - _startIndex];
}
template <typename T>
T const & Array<T>::operator[](int index) const
{
checkIndex(index);
return _array[index - _startIndex];
}
//SETTERS
template <typename T>
void Array<T>::setStartIndex(int index)
{ _startIndex = index; }
// ! WARNING: Setting length to a lower value than current will result in lost data
template <typename T>
void Array<T>::setLength(int length)
{
checkLength(length);
T* oldArray(_array);
int oldLength(_length);
_length = length;
init();
int lastIndex(oldLength < _length ? oldLength : _length);
copyArray(_array, oldArray, lastIndex);
delete [] oldArray;
}
//DECONSTRUCT <coolface.jpg>
template <typename T>
Array<T>::~Array()
{
delete [] _array;
}
// PRIVATE \\
template <typename T>
void Array<T>::init()
{
_array = new T[_length];
}
template <typename T>
void Array<T>::checkLength(int length) const
{
if (length < 0)
throw Exception("LENGTH_LESS_THAN_ZERO");
}
template <typename T>
void Array<T>::checkIndex(int index) const
{
if (index - _startIndex >= _length)
throw Exception("INDEX_LARGER_THAN_UPPER_BOUND");
if (index - _startIndex < 0)
throw Exception("INDEX_SMALLER_THAN_LOWER_BOUND");
}
template <typename T>
void Array<T>::copyArray(T * destination, T * source, int lastIndex)
{
while (lastIndex--)
destination[lastIndex] = source[lastIndex];
}
Sadly, I think you'll need two versions of Row: one for const Array and one for non-const. Just like the standard containers have iterators and const_iterators.