473,396 Members | 1,927 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Typedef-ing an iterator

Hey all,

I ran into an interesting little problem with defining an iterator in a
custom array class the other day. It goes something like this:

template <typename T>
class Array
{
public:
typedef T * iterator;

iterator begin();
...
};

template <typename T>
Array<T>::iterator Array<T>::begin()
{...}

I thought that this would be enough to get it to compile, but it said that
Array<T>::iterator was an implicit typename declaration and that that was
deprecated. So, my question is, how can I make this work without adding
typename to the return type of every custom typedef in my class (without
actually writing the method inside the class definition, please). Also,
more importantly, I think, what exactly is the problem with doing what I do
in the code above? It seems like Array<T>::iterator is pretty explicit as
to what it's referring to.

James
Jul 22 '05 #1
1 2016
James Aguilar wrote in news:cp**********@newsreader.wustl.edu in
comp.lang.c++:
Hey all,

I ran into an interesting little problem with defining an iterator in
a custom array class the other day. It goes something like this:

template <typename T>
class Array
{
public:
typedef T * iterator;

iterator begin();
...
};

template <typename T>
Array<T>::iterator Array<T>::begin()
{...}

I thought that this would be enough to get it to compile, but it said
that Array<T>::iterator was an implicit typename declaration and that
that was deprecated. So, my question is, how can I make this work
without adding typename to the return type of every custom typedef in
my class (without actually writing the method inside the class
definition, please).
You can't.
Also, more importantly, I think, what exactly is
the problem with doing what I do in the code above? It seems like
Array<T>::iterator is pretty explicit as to what it's referring to.


You may think that but a C++ parser isn't as clever as you are.

Maybe it could be made clever enough but that would add serveral
pages to an already 700+ page C++ Standard and a considerable amount
of complexity. Note that it is only reciently that we have had
access to compilers that get anywhere near to 100% conformance to
the Standard and that Standard is nearly 7 years old now.

If you want to discuss this more the place to do it is:

news:comp.std.c++

As that is where the "Why the language is this way" questions
should be discussed.

HTH.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: joe | last post by:
hi, after reading some articles and faq, i want to clarify myself what's correct(conform to standard) and what's not? or what should be correct but it isn't simply because compilers don't...
14
by: dreamcatcher | last post by:
I always have this idea that typedef a data type especially a structure is very convenient in coding, but my teacher insisted that I should use the full struct declaration and no further...
4
by: Chris | last post by:
I've lurked around long enough... Time to interract =) I'm trying to make sense of the following. I can't quite wrap my head around what this is actually doing: ------------- typedef enum {...
15
by: Merrill & Michele | last post by:
typedef struct { WORD versionNumber; WORD offset; } MENUITEMTEMPLATEHEADER; This is from vol 5 of unnamed platform's programmer's reference. I could make this conforming by enclosing...
16
by: burn | last post by:
Hello, i am writing a program under linux in c and compile my code with make and gcc. Now i have 4 files: init.c/h and packets.c/h. Each header-file contains some: init.h: struct xyz {
12
by: vvv | last post by:
Hi All, Do we have anything in .NET which is equivalent to C++'s Typedef . Regards, Vasanth
6
by: Alex | last post by:
Hello people, I am getting errors from VS2003 when working with typedef'ed types. For example, assume that I have a type T, defined in a 3rd party include file based on some condition #if...
15
by: Ian Bush | last post by:
Hi All, I'm a bit confused by the following which is causing one of our user's codes fail in compilation: typedef struct SctpDest_S; 1) Is this standard ? 2) If so ( or even if not so ! )...
12
by: Googy | last post by:
Hi!! Can any one explain me the meaning of following notations clearly : 1. typedef char(*(*frpapfrc()))(); frpapfrc f; 2. typedef int (*(arr2d_ptr)()); arr2d_ptr p; 3. typedef int...
16
by: mdh | last post by:
A quick ? :-) question about Typedefs. There is a very brief discussion about this in K&R ( p146). Googling this group, there is a surprising dearth of questions about these. From one of the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...
0
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...

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.