Problem with porting some STL code from VS to GCC

F

Frank Steinmetzger

Hello group,

I have a small program that has been written using Visual Studio. However, I
work with Linux and GCC. During porting I encountered a little problem that
I don't know how to solve. I should add that STL is pretty new to me ATM.


There is a class "cc":
template <int Dimension, typename ftype> class cc;

And a class "database", which holds a vector of cc:
template <int Dimension, typename ftype> class database {
[...]
private:
static std::vector<cc<Dimension, ftype>*> list;
}


The following is located in the destructor of database:

template <int Dimension, typename ftype>
database<Dimension, ftype>::~database()
{
[...]
for (std::vector<cc<Dimension, ftype>*>::iterator it = list.begin();
it!= list.end(); it++)
delete *it;
[...]
}

When compiling this, I get this error:
Curve.cpp: In destructor 'database<Dimension, ftype>::~database()':
Curve.cpp:630: error: expected `;' before 'it'
Curve.cpp:630: error: 'it' was not declared in this scope

(Line 630 is the one with the for loop).
For testing, I used std::vector<int*>::iterator in the loop and the error
disappeared. Hence cc<Dimension, ftype>* seems to be unknown or not
accepted as a template type for the vector, but how and why? Could you
please give me some advice?

Thanks in advance.
 
K

Kai-Uwe Bux

Frank said:
Hello group,

I have a small program that has been written using Visual Studio. However,
I work with Linux and GCC. During porting I encountered a little problem
that I don't know how to solve. I should add that STL is pretty new to me
ATM.


There is a class "cc":
template <int Dimension, typename ftype> class cc;

And a class "database", which holds a vector of cc:
template <int Dimension, typename ftype> class database {
[...]
private:
static std::vector<cc<Dimension, ftype>*> list;
}


The following is located in the destructor of database:

template <int Dimension, typename ftype>
database<Dimension, ftype>::~database()
{
[...]
for ( it =

iterator is a dependent name. Thus:

for ( typename std::vector<cc<Dimension, ftype>*>::iterator it =

should do it.
list.begin(); it!= list.end(); it++)
delete *it;
[...]
}

When compiling this, I get this error:
Curve.cpp: In destructor 'database<Dimension, ftype>::~database()':
Curve.cpp:630: error: expected `;' before 'it'
Curve.cpp:630: error: 'it' was not declared in this scope

(Line 630 is the one with the for loop).
For testing, I used std::vector<int*>::iterator in the loop and the error
disappeared. Hence cc<Dimension, ftype>* seems to be unknown or not
accepted as a template type for the vector, but how and why? Could you
please give me some advice?

Since you are within a template and the type

std::vector<cc<Dimension, ftype>*>

depends on the template parameters, the compiler cannot deduce that the
identifier std::vector<cc<Dimension, ftype>*>::iterator denotes a type
(after all, the vector-template could be specialized [setting asside that
vector resides in std]). Therefore, it needs a hint.


Best

Kai-Uwe Bux
 
F

Frank Steinmetzger

Kai-Uwe Bux schrob:
Frank said:
[..]
template <int Dimension, typename ftype>
database<Dimension, ftype>::~database()
{
[...]
for ( it =

iterator is a dependent name. Thus:

for ( typename std::vector<cc<Dimension, ftype>*>::iterator it =

should do it.

Indeed, it does. Great, thanks a lot.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top