B
bazley
I've been tearing my hair out over this:
#ifndef MATRIX2_H
#define MATRIX2_H
#include <QVector>
template<class T>
class Matrix2
{
public:
Matrix2() : m_rows(0), m_cols(0) {}
Matrix2(int rows,int cols) : m_rows(rows), m_cols(cols), m_data(rows *
cols) {}
Matrix2(int rows, int cols, QVector<T> data) : m_rows(rows),
m_cols(cols), m_data(data) {}
void resize(int rows, int cols)
{
m_data.resize(rows * cols);
m_rows = rows;
m_cols = cols;
}
T& operator()(int x, int y)
{
return m_data[x * cols + y];
}
const T& at(int x, int y) const
{
return m_data.at(x * cols + y);
}
int rows() const
{
return m_rows;
}
int cols() const
{
return m_cols;
}
private:
int m_rows, m_cols;
QVector< T > m_data;
};
#endif
offending line:
class DataTable {
..
..
Matrix2<int, int> m_data;
..
..
}
void DataTable::readData() {
..
..
m_data(row, varIndex) = DataTable::MISSING;
..
..
}
Error:
Matrix2.h: In member function 'T& Matrix2<T>:perator()(int, int)
[with T = int]':
DataTable.cpp:85: instantiated from here
Matrix2.h:22: error: invalid use of member (did you forget the '&' ?)
Matrix2.h: In member function 'const T& Matrix2<T>::at(int, int) const
[with T = int]':
DataTable.cpp:147: instantiated from here
Matrix2.h:27: error: invalid use of member (did you forget the '&' ?)
Thanks in advance!
#ifndef MATRIX2_H
#define MATRIX2_H
#include <QVector>
template<class T>
class Matrix2
{
public:
Matrix2() : m_rows(0), m_cols(0) {}
Matrix2(int rows,int cols) : m_rows(rows), m_cols(cols), m_data(rows *
cols) {}
Matrix2(int rows, int cols, QVector<T> data) : m_rows(rows),
m_cols(cols), m_data(data) {}
void resize(int rows, int cols)
{
m_data.resize(rows * cols);
m_rows = rows;
m_cols = cols;
}
T& operator()(int x, int y)
{
return m_data[x * cols + y];
}
const T& at(int x, int y) const
{
return m_data.at(x * cols + y);
}
int rows() const
{
return m_rows;
}
int cols() const
{
return m_cols;
}
private:
int m_rows, m_cols;
QVector< T > m_data;
};
#endif
offending line:
class DataTable {
..
..
Matrix2<int, int> m_data;
..
..
}
void DataTable::readData() {
..
..
m_data(row, varIndex) = DataTable::MISSING;
..
..
}
Error:
Matrix2.h: In member function 'T& Matrix2<T>:perator()(int, int)
[with T = int]':
DataTable.cpp:85: instantiated from here
Matrix2.h:22: error: invalid use of member (did you forget the '&' ?)
Matrix2.h: In member function 'const T& Matrix2<T>::at(int, int) const
[with T = int]':
DataTable.cpp:147: instantiated from here
Matrix2.h:27: error: invalid use of member (did you forget the '&' ?)
Thanks in advance!