By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,836 Members | 1,725 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,836 IT Pros & Developers. It's quick & easy.

typedef inside a template class

P: n/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
Jul 23 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Mr A wrote:
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

typedef typename std::list<Resource*>::iterator Iterator;


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

V
Jul 23 '05 #2

P: n/a
"Victor Bazarov" wrote
Mr A wrote:
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

typedef typename std::list<Resource*>::iterator Iterator;

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


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.

Jul 23 '05 #3

P: n/a
Uenal Mutlu wrote:
"Victor Bazarov" wrote
Mr A wrote:
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

typedef typename std::list<Resource*>::iterator Iterator;

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

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
Jul 23 '05 #4

P: n/a
"Victor Bazarov" wrote
Uenal Mutlu wrote:
"Victor Bazarov" wrote
Mr A wrote:

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

typedef typename std::list<Resource*>::iterator Iterator;
Visual Studio .NET doesn't like this.
Any ideas why? Is there a way around it?

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; // ********


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.

Jul 23 '05 #5

P: n/a
Uenal Mutlu wrote:
"Victor Bazarov" wrote
Uenal Mutlu wrote:
"Victor Bazarov" wrote
Mr A wrote:
>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

typedef typename std::list<Resource*>::iterator Iterator;

>Visual Studio .NET doesn't like this.
>Any ideas why? Is there a way around it?
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; // ********

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
Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.