🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2026

Re: typename versus typedef (was Re: typedef X;)

#2026
From: Andrew Koenig
Date: Mon, 25 Sep 1995 02:04
32 lines
1694 bytes
In article <MATT.95Sep23125440@Austern>
martelli@cadlab.cadlab.it (Alex Martelli) writes:

> avoiding the template author the chore of thinking up a dummy type
> name in this situation...?  Or am I missing something here...?

You're missing something.

	template<class T> class X {
		int a;
		void f() {
			T::Pointer (a);		// *
		}
	};

If T::Pointer is the name of a type, the line with the comment
declares a local variable inside function f that is of type T::Pointer.
If, on the other hand, T::Pointer is the name of a function, then
the line with the comment calls that function passing it the
member names `a' of class X.

This shows that in general it is necessary for the compiler to know
whether each identifier is the name of a type.  In the case of members
of template parameters, there's no easy way to know that in advance,
so the "typename" keyword provides a way to say.
-- 
				--Andrew Koenig
				  ark@research.att.com
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <DFFJz3.GB@research.att.com>
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
References: <Etay_Bogner-1709951504510001@metay_pc.stil.scitex.com> <MATT.95Sep20135311@physics2.Berkeley.EDU> <MATT.95Sep23125440@Austern>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
Date: 25 Sep 95 02:04:06 GMT
Approved: fjh@cs.mu.oz.au
Newsgroups: comp.std.c++
From: ark@research.att.com (Andrew Koenig)
Subject: Re: typename versus typedef (was Re: typedef X;)
Message-ID: <DFFJz3.GB@research.att.com>
Organization: AT&T Bell Laboratories, Murray Hill NJ
References: <Etay_Bogner-1709951504510001@metay_pc.stil.scitex.com> <MATT.95Sep20135311@physics2.Berkeley.EDU> <MATT.95Sep23125440@Austern>
X-Original-Date: Sun, 24 Sep 1995 22:04:14 GMT