Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

vector<>::iterator member of custom template class - Compile errors

Posted on 2002-04-14
7
Medium Priority
?
287 Views
Last Modified: 2013-12-14
Hi!  I'm currently using gcc to create a template class that contains a vector from the STL and an iterator of that vector.  However, when I compile it, I get the error "Syntax error before ;" on the line I declare the iterator in the header.  When I make the class a non-template, the error seems to disappear.  Any ideas what the problem is??

template< T_EDGE_WEIGHT >
class DijkstraTable
{
 public:
  DijkstraTable( const vector< VertexIndex > & VertIs );
  struct Dij_inf
  {
    VertexIndex v;
    T_EDGE_WEIGHT d;
    VertexIndex p;
    bool k;
  };
  Dij_inf& operator[]( VertexIndex iV );
 private:
  vector<Dij_inf> m_Table;
  vector<Dij_inf>::iterator mp_CurRow; // Syntax Error
};
0
Comment
Question by:Richwilli
  • 5
  • 2
7 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 6940396
Try

template< class T_EDGE_WEIGHT > // note the "class" statement
class DijkstraTable
{
public:
 DijkstraTable( const vector< VertexIndex > & VertIs );
 struct Dij_inf
 {
   VertexIndex v;
   T_EDGE_WEIGHT d;
   VertexIndex p;
   bool k;
 };
 Dij_inf& operator[]( VertexIndex iV );
private:
 vector<Dij_inf> m_Table;
 vector<Dij_inf>::iterator mp_CurRow; // Syntax Error
};
0
 
LVL 86

Expert Comment

by:jkr
ID: 6940397
Try

template< class T_EDGE_WEIGHT > // note the "class" statement
class DijkstraTable
{
public:
 DijkstraTable( const vector< VertexIndex > & VertIs );
 struct Dij_inf
 {
   VertexIndex v;
   T_EDGE_WEIGHT d;
   VertexIndex p;
   bool k;
 };
 Dij_inf& operator[]( VertexIndex iV );
private:
 vector<Dij_inf> m_Table;
 vector<Dij_inf>::iterator mp_CurRow; // Syntax Error
};
0
 
LVL 86

Expert Comment

by:jkr
ID: 6940399
Excuse the double post, but EE was a little "shaky" that moment...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:jkr
ID: 6940868
BTW, just in case I didn't mention - it works that way :o)
0
 

Author Comment

by:Richwilli
ID: 6942207
Well, leaving out "class" was just my typo.  It's actually there in my code;  I simply missed that line when I copied and added it myself afterward.  So unless there's something else different about your version I don't notice, it still doesn't work.  Are you using the gcc compiler?
0
 
LVL 86

Accepted Solution

by:
jkr earned 1200 total points
ID: 6942298
Tried it with both VC++ and g++, here's what I used:

#include <vector>

typedef int VertexIndex; // needed that, as no type info given in your sample

template< class T_EDGE_WEIGHT > // note the "class" statement
class DijkstraTable
{
public:
DijkstraTable( const vector< VertexIndex > & VertIs );
struct Dij_inf
{
  VertexIndex v;
  T_EDGE_WEIGHT d;
  VertexIndex p;
  bool k;
};
Dij_inf& operator[]( VertexIndex iV );
private:
vector<Dij_inf> m_Table;
vector<Dij_inf>::iterator mp_CurRow; // Syntax Error
};

0
 

Author Comment

by:Richwilli
ID: 6943095
You are quite right, it does work!  The problem must really lie elsewhere.  Thanks for your help.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question