typename vs class

E

EvilOldGit

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

Alf P. Steinbach

* (e-mail address removed):
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.
 
B

blangela

* (e-mail address removed):


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?
 
F

Fei Liu

blangela said:
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
 
K

kwikius

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, typename> class 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<int> x;
F<std::vector> f;

x.push_back(1);

f.foo(x);

}

regards
Andy Little
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

* (e-mail address removed):

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 T> class U>
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

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

template<template<typename T> class U>

I meant 'use class instead of typename'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top