473,395 Members | 1,756 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

g++: error: invalid use of member (did you forget the '&' ?)

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>::operator()(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!

Jul 23 '05 #1
7 12008
<ba****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...

T& operator()(int x, int y)
{
return m_data[x * cols + y];
Sholud be m_cols or cols()
}

const T& at(int x, int y) const
{
return m_data.at(x * cols + y);
Same here...
} [...] int m_rows, m_cols;


Ali

Jul 23 '05 #2
Ian
ba****@gmail.com wrote:
I've been tearing my hair out over this:

#ifndef MATRIX2_H
#define MATRIX2_H

#include <QVector>
template<class T>
class Matrix2 offending line:
class DataTable {
.
.
Matrix2<int, int> m_data;
.

Why two template arguments when Matrix2 only has one?

Ian
Jul 23 '05 #3
Oops -- typo. It's really just

Matrix2<int> m_data;

Jul 23 '05 #4
Figured it out: I used cols instead of m_cols. Of course, the compiler
helpfully gives me an "Invalid use of member" error which has no actual
meaning instead of saying the obvious "cols not defined"

Jul 23 '05 #5
"cols" is undefined in those functions. It should be m_cols

And what is QVector? Is it the same as std::vector?

Jul 23 '05 #6
Did you really mean

T& operator()(int x, int y)
{
return m_data[x * cols + y];
}

since there is no "cols" in scope?

In the future you might want to post the code you're having a problem
with, and add line number so we don't have to guess.

-- smw

Jul 23 '05 #7
<bh*******@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Figured it out: I used cols instead of m_cols. Of course, the compiler
helpfully gives me an "Invalid use of member" error which has no actual
meaning instead of saying the obvious "cols not defined"


You probably have figured this one out too, but for the sake of
completeness; cols was defined in your original code:

template<class T>
class Matrix2
{
[...]

T& operator()(int x, int y)
{

Invalid use of member is right here:

return m_data[x * cols + y];
}

[...]

Here is the member that is being used above in an invalid way:

int cols() const
{
return m_cols;
}
};

Ali

Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: shishir | last post by:
hi the following may be offtopic. gcc 3.3.3 compiler throws error like .....: error: invalid in-class initialization of static data member of non-integral type `const char' ...... error:...
4
by: db_from_mn | last post by:
Using Visual Studio, 2003: When I create a deployment project and try to install it, I get Installer Error 2705: Invalid Table, Could not be linked as tree. How can I debug this? It seems that I...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
0
by: HKSHK | last post by:
This list compares the error codes used in VB.NET 2003 with those used in VB6. Error Codes: ============ 3: This Error number is obsolete and no longer used. (Formerly: Return without GoSub)...
2
by: al3x4nder | last post by:
I`m need hanling XSLT errors in my script, before I`m use Sablotron, that has nice interface for it: ------------8<------------------ function ProduceXHTML($xml, $xsl){ $xh = xslt_create();...
12
by: mast2as | last post by:
Hi everyone... I have a TExceptionHandler class that is uses in the code to thow exceptions. Whenever an exception is thrown the TExceptionHander constructor takes an error code (int) as an...
7
by: The|Godfather | last post by:
Hi everybody, I read Scotte Meyer's "Effective C++" book twice and I know that he mentioned something specific about constructors and destructors that was related to the following...
2
by: Nick | last post by:
I'm learning C++ and ran into a compile error using Visual C++ 2005 Express on the following example program (located at http://www.cplusplus.com/doc/tutorial/templates.html): // template...
10
by: happyse27 | last post by:
Hi All, I got this apache errors(see section A1 and A2 below) when I used a html(see section b below) to activate acctman.pl(see section c below). Section D below is part of the configuration...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.