Connecting Tech Pros Worldwide Forums | Help | Site Map

Template Confusion: Short Code I promise!

Tomás
Guest
 
Posts: n/a
#1: May 25 '06

I can't understand why this won't compile:

template <class T>
struct Monkey {

typedef T Normal;

};

template <class T>
int Func()
{
typedef Monkey<T>::Normal SpecialType;

SpecialType k = SpecialType();

return k;
}

int main()
{
Func<int>();
}

-Tomás

Victor Bazarov
Guest
 
Posts: n/a
#2: May 25 '06

re: Template Confusion: Short Code I promise!


Tomás wrote:[color=blue]
> I can't understand why this won't compile:
>
> template <class T>
> struct Monkey {
>
> typedef T Normal;
>
> };
>
> template <class T>
> int Func()
> {
> typedef Monkey<T>::Normal SpecialType;[/color]

I think this is covered in the FAQ. See 'dependent names'.
[color=blue]
>
> SpecialType k = SpecialType();
>
> return k;
> }
>
> int main()
> {
> Func<int>();
> }[/color]

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


Tomás
Guest
 
Posts: n/a
#3: May 25 '06

re: Template Confusion: Short Code I promise!


Victor Bazarov posted:

[color=blue]
> I think this is covered in the FAQ. See 'dependent names'.[/color]


I'm a idiot!


Note to self: Next time I encounter a template error, repeat "typename" to
myself ten times.


Thanks Victor.


-Tomás
Diego Martins
Guest
 
Posts: n/a
#4: May 26 '06

re: Template Confusion: Short Code I promise!


I know sometimes "typename" and ".template " are necessary

but this sounds too bloated and cumbersome to me

why did C++ become so illegible?

Tomás wrote:[color=blue]
> Victor Bazarov posted:
>
>[color=green]
> > I think this is covered in the FAQ. See 'dependent names'.[/color]
>
>
> I'm a idiot!
>
>
> Note to self: Next time I encounter a template error, repeat "typename" to
> myself ten times.
>
>
> Thanks Victor.
>
>
> -Tomás[/color]

Luke Meyers
Guest
 
Posts: n/a
#5: May 27 '06

re: Template Confusion: Short Code I promise!


Diego Martins wrote:[color=blue]
> I know sometimes "typename" and ".template " are necessary
>
> but this sounds too bloated and cumbersome to me
>
> why did C++ become so illegible?[/color]

I highly suggest reading Stroustrup's informative and entertaining _The
Design and Evolution of C++_ (amazon.com/gp/product/0201543303), to
understand how issues like this have quite defensibly arisen. There
tend to be pretty good reasons for things like this, annoying as they
can sometimes be.

Luke

Closed Thread