Solved

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

Posted on 2002-04-14
7
279 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

822 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