|
-
Jul 10th, 2003, 01:40 AM
#1
Thread Starter
Lively Member
Matrix (well sort of) issue [Resolved]
PHP Code:
#define matrix Matrix
template <class Object>
class matrix
{
public:
matrix( int rows, int cols )
{
vOuter.resize(rows);
for(int i = 0; i < rows; i++)
vOuter[i].resize(cols);
NumOfRows = rows;
NumOfCols = cols;
}
matrix( const matrix &rhs)
{
vOuter(rhs.vOuter)
}
const vOuter<object> &operator[] (int row) const
{
return vOuter[row];
}
vector<Object> &operator[] (int row)
{
return vOuter[row];
}
int NumRows()
{
return NumOfRows;
}
int NumCols()
{
return NumOfCols;
}
private:
vector< vector<Object> > vOuter;
int NumOfRows;
int NumOfCols;
};
when trying to call the NumCols and NumRows functions I get these error:
MatrixTest.cpp(15) : error C2039: 'NumRows' : is not a member of 'Matrix<int>'
MatrixTest.cpp(16) : error C2039: 'NumCols' : is not a member of 'Matrix<int>'
I can't seem to figure out what I screwed up...
Last edited by Balron; Jul 10th, 2003 at 09:04 PM.
-
Jul 10th, 2003, 07:01 AM
#2
- Show your "MatrixTest.cpp" file.
- Why are you using #define matrix Matrix??
- the operator [] functions should return a vector<vector<object> >::reference / ::const_reference
- You don't need to define a copy constructor, the compiler will generate one for you.
- NumOfRows/Cols should be 'unsigned int's (or 'vector<object>::size_t's)
-
Jul 10th, 2003, 08:49 AM
#3
const vOuter<object> &operator[] (int row) const
That line is wrong. vOuter is not a type, so it can't be a return type.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jul 10th, 2003, 10:10 AM
#4
Thread Starter
Lively Member
Two reasons;
1) I'm just strange
2) It works =) Except for what I mentioned...I will try doing an uint but I don't think that will fix my problem...everything else but those two functions works perfectly.
MatrixTest.cpp does the following:
PHP Code:
#include "Library.h" // holds the Matrix, Vector, and a bunch of
// other functions and classes.
#include <iostream>
int main()
{
Matrix <int> Test(1,1);
cout << Test.NumRows();
cout << Test.NumCols();
}
-
Jul 10th, 2003, 12:02 PM
#5
Apparently it doesn't work. 
So....
Code:
const vector<object> &operator[] (int row) const
{
return vOuter[row];
}
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jul 10th, 2003, 12:49 PM
#6
Thread Starter
Lively Member
but thats not the problem...
the error is its not a member function if I take all but the constructor out, it still doesn't work.
But I changed it anyway, it still doesn't work =)
-
Jul 11th, 2003, 04:54 AM
#7
Next error is inconsistent capitalization of Object.
Finally, try using matrix instead of Matrix in the source file. Might be a thing.
Basically such #defines are bad. typedef is the way to go.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jul 11th, 2003, 07:26 AM
#8
Why is this resolved now?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jul 11th, 2003, 01:02 PM
#9
Thread Starter
Lively Member
Originally posted by CornedBee
Why is this resolved now?
Because I got help on another forum and they told me what I screwed up =)
-
Jul 13th, 2003, 12:16 PM
#10
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|