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

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 6042
* 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
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
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
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
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
by: Staffan Langin | last post by:
Hello, In the following code-snippet, template<class Base> class Foo : public Base {
8
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
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
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
by: Jess | last post by:
Hello, I've seen two forms of template declarations template<typename T> class A{...}; and template<class T>
10
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
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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.