473,734 Members | 2,764 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

typename usege problem ...

466
Hi all,
I have this member in a template class:

bool opsInsert(int nId, T pObj){
pairRet = insert(typename std::map<int,T> ::value_type(nI d, pObj)); }

which does compile with gcc but not with cl.exe (Windows).
If I remove the typename keyword, the code does not compile with gcc,
but compiles witc cl.exe....

The question: which is the standard way to call this function? Is there
any workaround to make compile with both compilers?

I know this is a compiler issue, but I hope you will help me ...

thanx,
stefan

Nov 3 '06 #1
6 1379
466 wrote:
Hi all,
I have this member in a template class:

bool opsInsert(int nId, T pObj){
pairRet = insert(typename std::map<int,T> ::value_type(nI d, pObj)); }

which does compile with gcc but not with cl.exe (Windows).
If I remove the typename keyword, the code does not compile with gcc,
but compiles witc cl.exe....

The question: which is the standard way to call this function?
The standard requires the typename keyword in this place.
Is there any workaround to make compile with both compilers?
Maybe use a macro, like:

#if compiler is vc++
#define TYPENAME
#else
#define TYPENAME typename
#endif

bool opsInsert(int nId, T pObj){
pairRet = insert(TYPENAME std::map<int,T> ::value_type(nI d, pObj)); }

It's ugly, but works.

Nov 3 '06 #2
466

Rolf Magnus wrote:
466 wrote:
Hi all,
I have this member in a template class:

bool opsInsert(int nId, T pObj){
pairRet = insert(typename std::map<int,T> ::value_type(nI d, pObj)); }

which does compile with gcc but not with cl.exe (Windows).
If I remove the typename keyword, the code does not compile with gcc,
but compiles witc cl.exe....

The question: which is the standard way to call this function?

The standard requires the typename keyword in this place.
Is there any workaround to make compile with both compilers?

Maybe use a macro, like:

#if compiler is vc++
#define TYPENAME
#else
#define TYPENAME typename
#endif

bool opsInsert(int nId, T pObj){
pairRet = insert(TYPENAME std::map<int,T> ::value_type(nI d, pObj)); }

It's ugly, but works.
Sure, as a ultimate solution ... :(
Thanx.

Nov 3 '06 #3
466 wrote:
Hi all,
I have this member in a template class:

bool opsInsert(int nId, T pObj){
pairRet = insert(typename std::map<int,T> ::value_type(nI d, pObj)); }

which does compile with gcc but not with cl.exe (Windows).
If I remove the typename keyword, the code does not compile with gcc,
but compiles witc cl.exe....
Get a version of the windows compiler that was published in the last
five years.
Nov 3 '06 #4
Maybe use a macro, like:

#if compiler is vc++
#define TYPENAME
#else
#define TYPENAME typename
#endif
You could use the macro
#define typename
as basically the older compilers don't know the typename keyword.
Be careful to make your #if specific to the current (and older)
versions of your compiler, as you don't want it to break when you do
upgrade...
Note also that the standard also allows typename as a synonym
(basically) for class in the template arguments,which also will not
work in yuour old compiler. i.e. you can write
template <typename MyType>

Nov 3 '06 #5
jim_taylor wrote:
>Maybe use a macro, like:

#if compiler is vc++
#define TYPENAME
#else
#define TYPENAME typename
#endif

You could use the macro
#define typename
as basically the older compilers don't know the typename keyword.
Except that in this case we recognize a certain compiler, that requires
typename in some places, doesn't care in other places, and flat out refuses
to recognize some cases where typename *is* required.

A very useful advice - use a compiler from this millennium - has alredy been
given by another poster.
Bo Persson
Nov 3 '06 #6
466 wrote:
Hi all,
I have this member in a template class:

bool opsInsert(int nId, T pObj){
pairRet = insert(typename std::map<int,T> ::value_type(nI d, pObj)); }

which does compile with gcc but not with cl.exe (Windows).
If I remove the typename keyword, the code does not compile with gcc,
but compiles witc cl.exe....

The question: which is the standard way to call this function? Is there
any workaround to make compile with both compilers?

I know this is a compiler issue, but I hope you will help me ...

thanx,
stefan
As has been noted, the standard requires "typename". However you could
replace the expression by the actual type of value_type, namely
std::pair< const int, T>. That should not require "typename".
Nov 4 '06 #7

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

Similar topics

1
3848
by: I wish | last post by:
I wrote some test code template <typename T> class A {}; class B{}; template < template <typename T> typename U > class C {}; int main( void )
2
2698
by: Chris Foster | last post by:
Hi, I'm having some difficulty using types which are defined in a base class inside a derived class. The problem crops up using template classes. The following test code encapsulates what I'd like to do, but doesn't compile with g++ (v3.3.3). //--------------------------------------------------------- // A = base class template <typename T>
1
1768
by: lutorm | last post by:
Hi all, I'm working on migrating my code from KCC to gcc, and I'm having some issues with "implicit typename" warnings from gcc. Essentially, what happens is described by this example: template <typename cell_data_type> class cell {}; template <typename a> class c1 { public: typedef cell<a> T_cell;
13
1713
by: Staffan Langin | last post by:
Hello, In the following code-snippet, template<class Base> class Foo : public Base {
1
1450
by: Carlos Martinez Garcia | last post by:
Hi all: I have the template class: template<typename InfoTabla> class TablaBusqueda { typename InfoTabla::Tabla TipoTabla; typename InfoTabla::Registro TipoRegistro; typename InfoTabla::TipoClave TipoClave; typedef map<TipoClave,TipoRegistro> Tabla; //line 9
8
1775
by: xuatla | last post by:
Hi, When I compile the following test code I got a warning about implicit typename. This happens in the member functions. Do you know the detail reason and solution? Thanks. - X ----------
1
1831
by: ma740988 | last post by:
I'm wading my way through Josuttis template text. I'm having a hard time understanding some things. So given: template <class T> class generic_traits { public: typedef T value_type; }; template <class T> class vector_traits {
2
1908
by: Dilip | last post by:
Folks I understand that the keyword typename is also used to indicate that a dependant parameter is a type. However I am a little unsure why I need typename in this following example: template<typename K, typename V> class MyMap { public:
7
2125
by: StephQ | last post by:
First of all: distinction of keywords typename and class in template arguments. Accoarding to a post in a well known moderated group: "There are three possibilities for template arguments: 1) type as in "template <typename T>" or "template <class T>" 2) non-type as in "template <int N>" 3) class template as in "template <template<typenameclass C>" "
0
8946
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8776
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
9310
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
9236
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,...
1
6735
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
6031
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
4550
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
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.