473,503 Members | 722 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

typename vs class

Are these just aliases ?
A few docs I've read imply that in certain case they aren't identical.

Mar 19 '07 #1
7 6049
* Ev********@googlemail.com:
Are these just aliases ?
No.

A few docs I've read imply that in certain case they aren't identical.
In a template parameter list they are identical, in all other cases they
aren't identical.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 19 '07 #2
On Mar 19, 11:26 am, "Alf P. Steinbach" <a...@start.nowrote:
* EvilOld...@googlemail.com:
Are these just aliases ?

No.
A few docs I've read imply that in certain case they aren't identical.

In a template parameter list they are identical, in all other cases they
aren't identical.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Where is typename used other than in a template paramater list?

Mar 19 '07 #3
blangela <Bo***********@telus.netwrote:
On Mar 19, 11:26 am, "Alf P. Steinbach" <a...@start.nowrote:
>In a template parameter list they are identical, in all other cases they
aren't identical.

Where is typename used other than in a template paramater list?
One example is in disambiguating dependant names, e.g.,

template <typename T>
class xyz {
void foo()
{
typename T::x my_x;
}
};

(example modified from
http://www.comeaucomputing.com/techt...ates/#typename
which is a handy reference)

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Mar 19 '07 #4
blangela wrote:
On Mar 19, 11:26 am, "Alf P. Steinbach" <a...@start.nowrote:
>* EvilOld...@googlemail.com:
>>Are these just aliases ?
No.
>>A few docs I've read imply that in certain case they aren't identical.
In a template parameter list they are identical, in all other cases they
aren't identical.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Where is typename used other than in a template paramater list?
Consider typename a more generic form to declare template parameters.
Use typename whenever you can instead of class.

Of course when you declare a class data structure, use 'class'. Only
place I am aware of that typename cannot replace class keyword.

Fei
Mar 19 '07 #5
On 19 Mar, 19:19, Fei Liu <fei...@aepnetworks.comwrote:
Of course when you declare a class data structure, use 'class'. Only
place I am aware of that typename cannot replace class keyword.

Other place is template template params e.g:

// for allocator
#include <memory>

// can't replace 'class' with typename below
template <template<typename, typenameclass Seq>
struct F{

template <typename T>
void foo( Seq<T,std::allocator<T const & seq)
{
std::cout << *seq.begin() <<'\n';
}
};

#include <vector>
#include <iostream>

int main()
{
std::vector<intx;
F<std::vectorf;

x.push_back(1);

f.foo(x);

}

regards
Andy Little

Mar 19 '07 #6
On 2007-03-19 19:26, Alf P. Steinbach wrote:
* Ev********@googlemail.com:
>Are these just aliases ?

No.

>A few docs I've read imply that in certain case they aren't identical.

In a template parameter list they are identical, in all other cases they
aren't identical.
There's also a case where you must use class instead of template, I ran
into this some time ago:

template<template<typename Tclass U>

--
Erik Wikström
Mar 19 '07 #7
On 2007-03-19 21:42, Erik Wikström wrote:
On 2007-03-19 19:26, Alf P. Steinbach wrote:
>* Ev********@googlemail.com:
>>Are these just aliases ?

No.

>>A few docs I've read imply that in certain case they aren't identical.

In a template parameter list they are identical, in all other cases they
aren't identical.

There's also a case where you must use class instead of template, I ran
into this some time ago:

template<template<typename Tclass U>
I meant 'use class instead of typename'.

--
Erik Wikström
Mar 19 '07 #8

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

Similar topics

1
3834
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
2677
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...
2
1827
by: Levent | last post by:
Please consider the following Parent and Child template classes: template <class T> class Parent { public: typedef T type; typedef T& ref; /* pack of typedefs */ };
1
1746
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: ...
13
1690
by: Staffan Langin | last post by:
Hello, In the following code-snippet, template<class Base> class Foo : public Base {
8
1764
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
1818
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; };...
7
2111
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)...
5
425
by: Jess | last post by:
Hello, I've seen two forms of template declarations template<typename T> class A{...}; and template<class T>
10
3511
by: jason.cipriani | last post by:
Is there any difference between declaring a template parameter as a "typename" or a "class"? E.g. template <class TT f() { } template <typename TT g() { } Thanks, Jason
0
7089
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
7282
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
7339
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
5581
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,...
1
5017
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...
0
4678
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...
0
3168
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...
0
1515
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
738
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.