Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A Matrix/Class issue...

Status
Not open for further replies.

Asharlin

Programmer
Jul 10, 2003
4
0
0
US
template <class Object>
class matrix
{
public:
matrix( int rows, int cols )
{
vOuter.resize(rows);
for(unsigned int i = 0; i < rows; i++)
vOuter.resize(cols);
NumOfRows = rows;
NumOfCols = cols;
}

matrix( const matrix &rhs)
{
vOuter(rhs.vOuter)
}

const vector<object> &operator[] (int row) const
{
return vOuter[row];
}

vector<Object> &operator[] (int row)
{
return vOuter[row];
}

unsigned int NumRows()
{
return NumOfRows;
}

unsigned int NumCols()
{
return NumOfCols;
}

private:
vector< vector<Object> > vOuter;
unsigned int NumOfRows;
unsigned int NumOfCols;
};

Whenever I call NumCols or NumRows such as below, it gives me the following 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>'

The code used to test them:

int main(int argc, char* argv[])
{
Matrix <int> Test(4,5);
Test[1][1] = 1;
Test[2][3] = 2;
int temp = 0;
cout << Test[1][1] << endl;
cout << Test[2][3] << endl;
cout << Test.NumRows() << endl;
cout << Test.NumCols() << endl;

return 0;
}

I posted this in another forum as well...but so far they haven't been able to help
 
I tried that code in VC++ 6.0 and it compiled fine.

I did have to change some of the code to keep the names the same case throughout. I don't know if you are coming from VB or if you just typed in the code quickly, but C++ code is case-sensitive. Maybe by defining the matrix class with a lower case 'm', then instantiating it as Matrix with an upper case m, your code is actually finding a different Matrix class and using that.

PS. I assume that you meant to say:

for(unsigned int i = 0; i < rows; i++)
vOuter.resize(cols);

and the message board converted it to italics =)
 
vOuter.resize(cols); is supposed to be
vOuter[i.].resize(cols); (remove the period)

I really should use preview =)
 
>> I really should use preview =)

Use the TGML [ code ] my code [ / code] tags to surround code and it will post correctly, see the TGML link at the bottom of the post entry window.
Code:
vOuter[i].resize(cols);

-pete
 
You beat me to mentioning that, oh well I changed that and it still does not work unfortunately. Maybe re-inventing the wheel for my use so I knew the ins and outs of the code I was using was a bad idea. And yes the first language I learned was VB and I am reasnobly new to VC++ which probably explains my case issues. I tried changing all the cases to lower case and it still fails. I also tried just doing the #define matrix Matrix. I think maybe I should try re-installing VS6 since it maybe something got corrupted somewhere.
 
Ya, the re-installation fixed it...I seem to have the worst luck =) Anyway, thanks for your help. =)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top