473,408 Members | 2,888 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,408 software developers and data experts.

Creating myclass::iterator type?

Hey

I have some code which I've been using on Microsoft VC++ for some time. Now
I wanted to port my application to Mac OS X which offers gcc and the build
fails.

Here is the troublesome code:

template<class T>
class CList
{
public:
typedef vector<T>::iterator iterator;
....
};

As you can see I want to use vector iterator and make it become an iterator
type for my class so I can use CList::iterator.

Gcc however says the following:

.../shared/list.h:47: warning: `std::vector<OLYLXQHQSPOQSPX,
std::allocator<_CharT> >::iterator' is implicitly a typename
.../shared/list.h:47: warning: implicit typename is deprecated, please
see the documentation for details

I wonder why this is deprecated? Does this mean it's not legal C++ ?

Thanks in advance.
-- John
Jul 22 '05 #1
3 2191

"John Smith" <jo********@x-formation.com> wrote in message
news:41*********************@dread16.news.tele.dk. ..
Hey

I have some code which I've been using on Microsoft VC++ for some time. Now I wanted to port my application to Mac OS X which offers gcc and the build
fails.

Here is the troublesome code:

template<class T>
class CList
{
public:
typedef vector<T>::iterator iterator;
...
};

As you can see I want to use vector iterator and make it become an iterator type for my class so I can use CList::iterator.

Gcc however says the following:

../shared/list.h:47: warning: `std::vector<OLYLXQHQSPOQSPX,
std::allocator<_CharT> >::iterator' is implicitly a typename
../shared/list.h:47: warning: implicit typename is deprecated, please
see the documentation for details

I wonder why this is deprecated? Does this mean it's not legal C++ ?


Yes, use this instead

typedef typename vector<T>::iterator iterator;

typename is obligatory here, but some compilers do not insist on it.

The reason for requiring typename is that by default C++ assumes iterator is
a static data member. Because vector is a template the compiler cannot look
up the definition of vector<T>::iterator (because the compiler does not know
what T is) so it must be told that iterator is a type name.

john
Jul 22 '05 #2
"John Smith" <jo********@x-formation.com> wrote in message
news:41*********************@dread16.news.tele.dk. ..
Hey

I have some code which I've been using on Microsoft VC++ for some time.
Now
I wanted to port my application to Mac OS X which offers gcc and the build
fails.

Here is the troublesome code:

template<class T>
class CList
{
public:
typedef vector<T>::iterator iterator;
...
};


You're using VC6, right? I just tried your code with VC7.1 (2003) and it
gave the following errors:

cpptest.cpp(9) : warning C4346: 'std::vector<_Ty>::iterator' : dependent
name is not a type
prefix with 'typename' to indicate a type
cpptest.cpp(10) : see reference to class template instantiation 'CList<T>'
being compiled
cpptest.cpp(9) : error C2144: syntax error : 'std::iterator' should be
preceded by ';'
cpptest.cpp(9) : fatal error C1903: unable to recover from previous
error(s); stopping compilation

The point is that when the parser first encounters your reference to
vector<T>::iterator, it doesn't know if it's a type or a static member. VC6
would allow this anyway and just assume it's a type, but that's non-standard
behaviour. VC7 and up, like gcc, don't allow this. As indicated, "prefix
with 'typename' to indicate a type":
typedef typename vector<T>::iterator iterator;

--
Unforgiven

Jul 22 '05 #3
Thanks to both your answers.

To answer forgiven, yes I did use VC6 which works quite ok.

Thank you both for your suggestions. The code works fine now :)

-- John
Jul 22 '05 #4

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

Similar topics

7
by: Prawit Chaivong | last post by:
Hi, gurus Is it safe to do this in function? 'return &(*iterator)'; And iterator is std::set<something>::iterator Regards,
4
by: John | last post by:
I have a function declaration that gives an error while compiling. Can anyone help me figure this one out? inline void create(const std::vector< myclass >& plist, std::vector< myclass...
1
by: Jean Stax | last post by:
Hi ! I created a sample library project. In my second project I reference this library and make the following call, which returns "undefined value": Type myType =...
0
by: Richard Bell | last post by:
Hosting process is dllhost. Type reference is obtained by a call to System.GetType(). Declaring assembly does not have a strong name and is located in DEVPATH. Assembly is loaded and type reference...
3
by: Søren M. Olesen | last post by:
Hi How do I dynamically create a type of System.Int32 with the value 123?? I've tried the following: Dim keyci As ConstructorInfo = Type.GetType("System.Int32").GetConstructor(New Type()...
11
by: Mateusz Loskot | last post by:
Hi, I have a simple question about naming convention, recommeded names or so in following case. I have a class which is implemented with one of STL container (aggregated) and my aim is to...
4
by: sternr | last post by:
Hey, I have the following class: public Child<T> { //Some Code } Can I (using Reflection or any other way) create a Child object in runtime without knowing what is T? like this:
4
by: michael | last post by:
Hi All, I have : #include <iostream> #include <list> using std::cout; using std::list; using std::endl;
8
by: JackC | last post by:
Hi, If i have a std::vector containing pointers, then iterate through the vector and im slightly confused as to how i use the item from the iterator? for example, vector<MyClass*myvector;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...

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.