Solved

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

Posted on 2002-04-14
7
284 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

624 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