By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 833 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

typename vs class

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

Mar 19 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
* 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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.