473,802 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating myclass::iterat or 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>::iter ator 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<OL YLXQHQSPOQSPX,
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 2222

"John Smith" <jo********@x-formation.com> wrote in message
news:41******** *************@d read16.news.tel e.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>::iter ator 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<OL YLXQHQSPOQSPX,
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>::iter ator 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>::iter ator (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******** *************@d read16.news.tel e.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>::iter ator 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<_T y>::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>::iter ator, 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>::iter ator 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
4495
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
2407
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 >::iterator left, std::vector< myclass >::iterator right); x.hpp:153: error: `class std::vector<myclass, D>, std::alloca
1
4009
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 = Type.GetType("SampleLib.MyClass"); My guess was that the function fails because my library isn't loaded yet.
0
1048
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 obtained. However, call to Activator.CreateInstance(Type) throws TargetInvocationException. The type has only a default constructor and no initialised fields. Interestingly, if I attach the debugger to hosting process, the type instance is...
3
2066
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() {Type.GetType("System.Int32")}) Dim key As Object = keyci.Invoke(New Object() {"123"}) however it doesn't seem to work....
11
1950
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 expose iterators to enable user of my class to iterate through this container content. Here is a piece of code: class A;
4
1329
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
1467
by: michael | last post by:
Hi All, I have : #include <iostream> #include <list> using std::cout; using std::list; using std::endl;
8
1781
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
9562
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
10538
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
10305
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...
0
9115
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
7598
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
6838
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
5494
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
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2966
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.