Results 1 to 10 of 10

Thread: Matrix (well sort of) issue [Resolved]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Posts
    78

    Matrix (well sort of) issue [Resolved]

    PHP Code:
        #define matrix Matrix

        
    template <class Object>
            class 
    matrix
            
    {    
                public:
                    
    matrixint rowsint cols )
                    {
                        
    vOuter.resize(rows);
                        for(
    int i 0rowsi++)
                            
    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:
                    
    vectorvector<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.
    - Your Local Drunk
    AIM: Asharlin
    YIM: Asharlin
    MSN: [email protected]
    ICQ: 177568857

  2. #2
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771
    - 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)

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Posts
    78
    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 <intTest(1,1);
           
    cout << Test.NumRows();
           
    cout << Test.NumCols();
          

    - Your Local Drunk
    AIM: Asharlin
    YIM: Asharlin
    MSN: [email protected]
    ICQ: 177568857

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Posts
    78
    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 =)
    - Your Local Drunk
    AIM: Asharlin
    YIM: Asharlin
    MSN: [email protected]
    ICQ: 177568857

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Posts
    78
    Originally posted by CornedBee
    Why is this resolved now?
    Because I got help on another forum and they told me what I screwed up =)
    - Your Local Drunk
    AIM: Asharlin
    YIM: Asharlin
    MSN: [email protected]
    ICQ: 177568857

  10. #10
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    What was it?
    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
  •  



Click Here to Expand Forum to Full Width