473,783 Members | 2,418 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

typedef inside a template class

Hi!
I'm trying to do the following:

emplate <typename Resource>
class ResourceManager
{
public:
typedef std::list<Resou rce*>::iterator Iterator;
typedef std::list<Resou rce*>::const_it erator ConstIterator;

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

/M
Jul 23 '05 #1
5 2398
Mr A wrote:
Hi!
I'm trying to do the following:

emplate <typename Resource>
class ResourceManager
{
public:
typedef std::list<Resou rce*>::iterator Iterator;
typedef std::list<Resou rce*>::const_it erator ConstIterator;
Try

typedef typename std::list<Resou rce*>::iterator Iterator;


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

V
Jul 23 '05 #2
"Victor Bazarov" wrote
Mr A wrote:
I'm trying to do the following:

emplate <typename Resource>
class ResourceManager
{
public:
typedef std::list<Resou rce*>::iterator Iterator;
typedef std::list<Resou rce*>::const_it erator ConstIterator;


Try

typedef typename std::list<Resou rce*>::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<Resou rce*>::iterator Iterator;
typedef std::list<Resou rce*>::const_it erator ConstIterator;
should compile.

Jul 23 '05 #3
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<Resou rce*>::iterator Iterator;
typedef std::list<Resou rce*>::const_it erator ConstIterator;


Try

typedef typename std::list<Resou rce*>::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<Resou rce*>::iterator Iterator;
typedef std::list<Resou rce*>::const_it erator 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>::i terator 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>::i terator Iterator; // ********

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

V
Jul 23 '05 #4
"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<Resou rce*>::iterator Iterator;
typedef std::list<Resou rce*>::const_it erator ConstIterator;

Try

typedef typename std::list<Resou rce*>::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<Resou rce*>::iterator Iterator;
typedef std::list<Resou rce*>::const_it erator 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>::i terator 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>::i terator 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
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<Resou rce*>::iterator Iterator;
>typedef std::list<Resou rce*>::const_it erator ConstIterator;

Try

typedef typename std::list<Resou rce*>::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<Resou rce*>::iterator Iterator;
typedef std::list<Resou rce*>::const_it erator 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<clas s T> class R {
typedef std::list<T>::i terator 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>::i terator 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3016
by: Roger Leigh | last post by:
Although I've got over most of my template-related problems, I'm having trouble when I started to use default template parameters. For template type T, I've typedef'd this as object_type and then typedef'd std::vector<T> menu_list. This doesn't seem to work though: 40 template<typename W> 41 class ObjectOptionMenuDescribeObject 42 { 43 public:
2
1650
by: marco | last post by:
the problem: I use a typedef inside a class template, than I use this type (dim_v<N1>::Type) to define the argument of a template function f but when I call this function from main, the compiler (gcc 3.4.1) tell me: "no matching function found". If someone, more expert than me, could tell me what is wrong I would be very happy
0
1481
by: Imre | last post by:
I'm planning to create a macro-based property system (reflection, automatic serializing for properties, that kind of stuff). The system would involve writing some PROPERTY(propName) macros between a BEGIN_CLASS(ThisClass) and an END_CLASS() macro. The PROPERTY macros should somehow know ThisClass, and that's where it start to get tricky. A #define ThisClass would of course help, but I'd rather make it part of the BEGIN_CLASS macro, and...
7
483
by: Gurikar | last post by:
Does typedef vector<std::string> vNames; creates vector object?
7
2150
by: Tony Johansson | last post by:
Hello Experts! I have the following Array template class see below. I execute these three statements statement 1: Array<int> x(5); statement 2: cin >>x; statement 3: Array<int>::element_type y = x; but I can't understand the last one which is Array<int>::element_type y = x; We have a typedef T element_type; in the template Array class see below
1
18982
by: Joel Kullberg | last post by:
Hi! I have a question for u guys! I would like to use the c++ package ITK (www.itk.org) for internal handling och data and functions in a dataset3D class of mine! I also want to use a base class to be able to use all kinds of datasets (2D/3D/4D...) ----------------------------------------------------------- class dataset_base{ public: virtual void printDataInfo()=0;
2
2207
by: Patrick Kowalzick | last post by:
Hello NG, sorry to bother again, but I am a lit surprised that I got no answer on my post (attached below). So I refined the code a little bit :-). If there is a typedefed class X inside a class Y which has the same typedef name and used in the form "Instance_Y::type::type" MSVC7.1 fails to compile. See example below.
4
2482
by: Sacha | last post by:
I'm aware, that up to date, "typedef templates" are not defined within the C++ standard. The seemingly common workaround is this: template <class T> struct MyTypeDef { /* ultimately I need something like this: MyOtherClass<T> Type; but let's keep it simple for the moment */
13
1856
by: miaohua1982 | last post by:
the code is as follows: #include <iostream> using namespace std; typedef double DOUBLE; class Screen { public: typedef int DOUBLE;
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10081
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6735
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.