Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Templated classes in gnucpp4.0.2 (http://www.go4expert.com/forums/templated-classes-gnucpp402-t16847/)

CMGmadison 8Apr2009 23:04

Templated classes in gnucpp4.0.2
 
I just registered for these forums because there seem to be a number of knowledgeable and helpful c++ people here, and I'm fighting a c++ problem that is beyond my knowledge. I'm a fairly novice coder, and I've been tasked with debugging a code written by my phd advisor a few years ago. He swears it used to compile, but it no longer does. It's a pretty large program, so I'll just include the part that I'm having problems with right now, and I think it has to do with the way the class is templated. As in, it used to be okay to do it this way, but it no longer is with gnucpp4.0.2.

Code:

template<class T>                      // line 215
void matrix<T>::erase(const int id)    // line 216
{                                      // line 217
  std::vector<std::vector<T> >::iterator p=mat.begin()+id;  // line 218
  mat.erase(p);                        // line 219
}                                      // line220

template<class T>                      // line 222
void matrix<T>::erase_col(const int id) // line 223
{                                      // line 224
  for (int i=0;i<mat.size();i++){      // line 225
          std::vector<T>::iterator p=mat[i].begin()+id; // line 226
    if (id<mat[i].size()) mat[i].erase(p); // line 227
  }                                    // line 228
}

The error messages are:

Code:

matrix.h: In member function `void matrix<T>::erase(int)':
matrix.h:218: error: expected `;' before "p"
matrix.h:219: error: `p' was not declared in this scope
matrix.h: In member function `void matrix<T>::erase_col(int)':
matrix.h:226: error: expected `;' before "p"
matrix.h:227: error: `p' was not declared in this scope
make: *** [convasp.o] Error 1

Any thoughts or suggestions would be hugely appreciated. Thanks!

PS if any of you are denizens of other C++ forums you may notice that I'm posting this in other places too. I don't mean to spam, but this is kind of urgent.


All times are GMT +5.5. The time now is 19:26.