473,569 Members | 2,542 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 6059
* Ev********@goog lemail.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.now rote:
* EvilOld...@goog lemail.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.now rote:
>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.now rote:
>* EvilOld...@goog lemail.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...@aepnetw orks.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<typen ame, typenameclass Seq>
struct F{

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

#include <vector>
#include <iostream>

int main()
{
std::vector<int x;
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********@goog lemail.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<templa te<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********@goog lemail.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<templa te<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
3842
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
2684
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...
2
1830
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
1753
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
1700
by: Staffan Langin | last post by:
Hello, In the following code-snippet, template<class Base> class Foo : public Base {
8
1768
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
1823
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 {
7
2116
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...
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
3523
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
7700
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...
0
7614
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...
0
8125
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...
1
7676
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...
0
7974
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5513
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...
0
3653
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...
1
2114
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 we have to send another system
0
938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.