Solved

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

Posted on 2002-04-14
7
277 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
Comment Utility
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
Comment Utility
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
Comment Utility
Excuse the double post, but EE was a little "shaky" that moment...
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 86

Expert Comment

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

Author Comment

by:Richwilli
Comment Utility
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 300 total points
Comment Utility
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
Comment Utility
You are quite right, it does work!  The problem must really lie elsewhere.  Thanks for your help.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

  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 …
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now