Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: For god's sake how do I get rid of this warning!

Reply
Thread Tools

Re: For god's sake how do I get rid of this warning!

 
 
Ulrich Eckhardt
Guest
Posts: n/a
 
      09-12-2003
Curt wrote:
> Ulrich Eckhardt <(E-Mail Removed)> wrote :
> [explicit 'typename' required]
>
> I wonder what ivory-tower insanely contrived "problem" it solves.
>


Hmmm, let's see if I can make up one (I just remember having been shown a
valid example).


struct foo
{
enum{ value = 1};
};

struct bar
{
typedef float value;
};

struct baz
{
long value();
};

template< class T> void foobarr()
{
typedef /*typename*/ T::value value_type;
};

As you see, there are three different things being referred to by T::value,
an integral, a type and a memberfunction.

Hmmm, I think I'm stuck, I don't remember the rest of it.
Anyway, I set a follow up to clc++, maybe the amassed brainpower there can
help.

cheers

Uli

--
Questions ?
see C++-FAQ Lite: http://parashift.com/c++-faq-lite/ first !

 
Reply With Quote
 
 
 
 
tom_usenet
Guest
Posts: n/a
 
      09-12-2003
On Fri, 12 Sep 2003 15:43:16 +0200, Ulrich Eckhardt
<(E-Mail Removed)> wrote:

>Curt wrote:
>> Ulrich Eckhardt <(E-Mail Removed)> wrote :
>> [explicit 'typename' required]
>>
>> I wonder what ivory-tower insanely contrived "problem" it solves.
>>

>Hmmm, I think I'm stuck, I don't remember the rest of it.
>Anyway, I set a follow up to clc++, maybe the amassed brainpower there can
>help.


There are a number of advantages that I can think of:

1. It is obvious by looking at source code that a particular dependent
name is supposed to be a type, rather than a static member or whatever
(this doesn't apply to the original example).

2. It allows syntax checking of template definitions that haven't been
instantiated. Experience has shown that whenever any significant
template source code base has been run through a compiler with
template syntax checking for the first time, a large number of errors
and typos have been found in templates that hasn't yet been
instantiated by the authors during testing.

3. It is enforced that a particular dependent name is be a type,
template or whatever, rather than depending upon a particular
instantiation context.

4. As for why typename is still required when it is "obvious" that a
typename is being named (e.g. in a typedef), consistency and ease of
parsing are the reasons.

There are enough pragmatic people in the C++ standards committee to
ensure that "ivory-tower insanely contrived "problem" solving"
features don't tend to make it into the standard.

Tom
 
Reply With Quote
 
 
 
 
C Johnson
Guest
Posts: n/a
 
      09-12-2003
> > I wonder what ivory-tower insanely contrived "problem" it solves.
[snip]
> Hmmm, let's see if I can make up one (I just remember having been shown a
> valid example).

[snip]
> template< class T> void foobarr()
> {
> typedef /*typename*/ T::value value_type;
> };


Names dependent on a template parameter is assumed not to name a type
unless the applicable name finds a type name or the name is qualified
by the keyword typename:

typedef typename T::value value_type;
value_type v1;
typename T::value v2
T::value v3 // Error - T::value is not a type name
// so in effect 'value v3' makes no sense

The "ivory-tower insanely contrived 'problem' it solves" is that you
can't declare types without a type.

-CJohnson
 
Reply With Quote
 
Curt
Guest
Posts: n/a
 
      09-13-2003
> T::value v3 // Error - T::value is not a type name
> // so in effect 'value v3' makes no sense
>
> The "ivory-tower insanely contrived 'problem' it solves" is that you
> can't declare types without a type.
>
> -CJohnson


Yes I did some research and found a similair example, I always look up
stuff in c++ that I've never seen before.

Since my personal belief is that non-trivial template use is an act of
evil. That there is a special place in hell for people who "get cute" with
complicated syntax, thus making code a maintenance nightmare. I can see why
it never came up before.

One of these days I'm going to write a book- "Problems you should never
have, and the solutions to them"

In any case I've filed it away for future use, thats why I love
programming- not a day goes by that I don't learn something new.

-Curt
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
1D Mk III "ERROR 99" (For Christ's Sake Already!!!) =?iso-8859-1?Q?Rita_=C4_Berkowitz?= Digital Photography 2 06-15-2007 01:12 AM
for the sake of args =?Utf-8?B?cm9kY2hhcg==?= ASP .Net 2 10-18-2006 01:01 PM
Fors Gods sake neville Computer Support 7 06-15-2005 04:39 PM
20D: ART FOR ANT'S SAKE !!! Annika1980 Digital Photography 4 04-30-2005 01:23 AM



Advertisments