can't figure this error out

This is a discussion on can't figure this error out within the C++ Programming forums, part of the General Programming Boards category; i got this code from microsoft on a 2d matrix. perhaps its not working because im using Dev-C++/gcc Code: #include ...

  1. #1
    i want wookie cookies the Wookie's Avatar
    Join Date
    Oct 2002
    Posts
    455

    can't figure this error out

    i got this code from microsoft on a 2d matrix. perhaps its not working because im using Dev-C++/gcc

    Code:
    #include <vector>
    using namespace std;
    
    template <class T>
    class C2DVector
    {
    public:
       C2DVector():m_dimRow(0), m_dimCol(0){;}
       C2DVector(int nRow, int nCol) {
          m_dimRow = nRow;
          m_dimCol = nCol;
          for (int i=0; i < nRow; i++){
             vector<T> x(nCol);
             int y = x.size();
             m_2DVector.push_back(x);
          }
       }
       void SetAt(int nRow, int nCol, const T& value) throw(std::out_of_range); {
          if(nRow >= m_dimRow || nCol >= m_dimCol)
             throw out_of_range("Array out of bound");
          else
             m_2DVector[nRow][nCol] = value;
       }
       T GetAt(int nRow, int nCol) {  //ERROR ON THIS LINE
          if(nRow >= m_dimRow || nCol >= m_dimCol)
             throw out_of_range("Array out of bound");
          else
             return m_2DVector[nRow][nCol];
       }
    
    <snip>
    error: 24 C:\Nabeel\segment_model\C2dvector.h
    parse error before `)' token

    if you want me to post the rest of the code i for the class, i will. i saved it in a file called C2DVector.h, maybe that has something to do with it?

    -Nabeel

  2. #2
    Registered User Casey's Avatar
    Join Date
    Jun 2003
    Posts
    47
    I got a parse error here
    Code:
    void SetAt(int nRow, int nCol, const T& value) throw(std::out_of_range); {
    That semicolon shouldn't be there. Try removing it and see what happens.

  3. #3
    i want wookie cookies the Wookie's Avatar
    Join Date
    Oct 2002
    Posts
    455
    hmm, i did that, still gives the same error.

  4. #4
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    setAt/getAt are not templated functions. Put a 'template<class T>' before them.

    Edit: Nevermind, I can't count braces.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  5. #5
    Nor
    Nor is offline
    h ֆhr s Nor's Avatar
    Join Date
    Nov 2001
    Posts
    299
    void SetAt(int nRow, int nCol, const T& value) throw(stdut_of_range);

    do you need the std:: in this line. you already declared that your using this namespace
    Try to help all less knowledgeable than yourself, within
    the limits provided by time, complexity and tolerance.
    - Nor

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 3 dimensional figure volume
    By thekautz in forum C++ Programming
    Replies: 2
    Last Post: 01-20-2009, 04:22 PM
  2. trying to figure out someone's code for a plugin
    By paulpars in forum C++ Programming
    Replies: 4
    Last Post: 07-20-2006, 10:57 AM
  3. newb to C, cant figure something out.
    By Phate4219 in forum C Programming
    Replies: 16
    Last Post: 03-06-2006, 12:47 AM
  4. ahh i can't figure out this loop
    By blindleaf in forum C Programming
    Replies: 1
    Last Post: 03-18-2003, 08:42 AM
  5. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 11:01 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21