Solved

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

Posted on 2002-04-14
7
281 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: 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 300 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

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!

Question has a verified solution.

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

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

735 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