Thread overview
malformed template with form g(f(x))
Jun 28, 2003
Richard Grant
Jun 29, 2003
Christof Meerwald
Jun 29, 2003
Richard Grant
Jun 29, 2003
Richard Grant
Jul 05, 2003
Rajiv Bhagwat
June 28, 2003
template <class T> struct A {};
template <class T> struct B {};
template <class T> A<B<T>> fn() { return A<B<T>>(); }

int main() {
//Error: malformed template declaration
fn<int>();
}

Richard


June 29, 2003
On Sat, 28 Jun 2003 21:29:06 +0000 (UTC), Richard Grant wrote:
> template <class T> struct A {};
> template <class T> struct B {};
> template <class T> A<B<T>> fn() { return A<B<T>>(); }

should be:
template <class T> A<B<T> > fn() { return A<B<T> >(); }

> int main() {
> //Error: malformed template declaration
> fn<int>();
> }


Well, the error message could be a bit clearer, but your code is not legal C++.


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw@jabber.at mailto cmeerw at web.de

...and what have you contributed to the Net?
June 29, 2003
In article <bdm0cd$2jkm$1@digitaldaemon.com>, Christof Meerwald says...
>
>On Sat, 28 Jun 2003 21:29:06 +0000 (UTC), Richard Grant wrote:
>> template <class T> struct A {};
>> template <class T> struct B {};
>> template <class T> A<B<T>> fn() { return A<B<T>>(); }
>
>should be:
>template <class T> A<B<T> > fn() { return A<B<T> >(); }

So the extra space helps identify the type? That's a little odd. But is in keeping with typeid having a space as I pointed out some time ago.

>
>> int main() {
>> //Error: malformed template declaration
>> fn<int>();
>> }
>
>
>Well, the error message could be a bit clearer, but your code is not legal C++.

What is illegal about the code above?

Richard


June 29, 2003
In article <bdn8d1$nf3$1@digitaldaemon.com>

Richard Grant says...
not very much ;)

ok forget about that last post. And thanks for correction.

Richard


July 05, 2003
The compiler uses "maximal munch" i.e.. grabs as many characters as possible to form a token, and ">>" is a valid operator. So, to use <T> followed by another >, you must leave a space in between.

Rajiv


"Richard Grant" <fractal@clark.net> wrote in message news:bdndm0$t6h$1@digitaldaemon.com...
> In article <bdn8d1$nf3$1@digitaldaemon.com>
>
> Richard Grant says...
> not very much ;)
>
> ok forget about that last post. And thanks for correction.
>
> Richard
>
>