typedef inside a template class

M

Mr A

Hi!
I'm trying to do the following:

emplate <typename Resource>
class ResourceManager
{
public:
typedef std::list<Resource*>::iterator Iterator;
typedef std::list<Resource*>::const_iterator ConstIterator;

Visual Studio .NET doesn't like this.
Any ideas why? Is there a way around it?

/M
 
V

Victor Bazarov

Mr said:
Hi!
I'm trying to do the following:

emplate <typename Resource>
class ResourceManager
{
public:
typedef std::list<Resource*>::iterator Iterator;
typedef std::list<Resource*>::const_iterator ConstIterator;
Try



Visual Studio .NET doesn't like this.
Any ideas why? Is there a way around it?


V
 
U

Uenal Mutlu


I would say it is a compiler bug because both
typedef std::list<Resource*>::iterator Iterator;
typedef std::list<Resource*>::const_iterator ConstIterator;
should compile.
 
V

Victor Bazarov

Uenal said:
I would say it is a compiler bug because both
typedef std::list<Resource*>::iterator Iterator;
typedef std::list<Resource*>::const_iterator ConstIterator;
should compile.

It should? According to what?

Anyway, if you think that it should compile, then you need to report a bug
to Comeau Computing because their compiler refuses to compile this:
----------------------------
#include <list>

template<class T> class R {
typedef std::list<T>::iterator Iterator; // ***************
std::list<T> l;
public:
R() {}
Iterator begin() { return l.begin(); }
};

int main() {
R<int> r;
r.begin();
}
-----------------------------
but compiles it fine if I change the line with asterisks to

typedef typename std::list<T>::iterator Iterator; // ********

(unless of course the culprit is the number of asterisks...)

V
 
U

Uenal Mutlu

It should? According to what?

Anyway, if you think that it should compile, then you need to report a bug
to Comeau Computing because their compiler refuses to compile this:
----------------------------
#include <list>

template<class T> class R {
typedef std::list<T>::iterator Iterator; // ***************
std::list<T> l;
public:
R() {}
Iterator begin() { return l.begin(); }
};

int main() {
R<int> r;
r.begin();
}

It is not consistent with the normal usage of typedef.
Normally one has always written such:

typedef int MyType;

struct S {};
typedef S MyStructType;

but now you say this must be rewritten to
typedef typename int MyType;
typedef typename S MyStructType;

But it is not compatible to existing code.
Either it is a bug of Microsoft's .NET compiler and Comeau's (I haven't checked the latter)
or you need to show me where in the standards this has changed.
 
V

Victor Bazarov

Uenal said:
It is not consistent with the normal usage of typedef.

What's "normal"?
Normally one has always written such:

typedef int MyType;

struct S {};
typedef S MyStructType;

Yes, both 'int' and 'S' are _independently_ type-ids.
but now you say this must be rewritten to
typedef typename int MyType;
typedef typename S MyStructType;

No, I said no such thing.
But it is not compatible to existing code.

WTF are you talking about?
Either it is a bug of Microsoft's .NET compiler and Comeau's (I haven't checked the latter)
or you need to show me where in the standards this has changed.

The Standard requires the word 'typename' with any _dependent_ identifier
that is to be recognized as a type. Search the news archives and you will
find many discussions on this.

V
 

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

Forum statistics

Threads
474,293
Messages
2,571,500
Members
48,188
Latest member
GerardRush

Latest Threads

Top