On 13 mai, 10:04, James Kanze <james.ka...@gmail.com> wrote:
> On May 13, 1:53 am, "Alessandro [AkiRoss] Re" <akirosspo...@gmail.com>
> wrote:
>
> > While developing a policy-based application, I tried a code
> > like this one (which is real code).
> > I'm using g++ 4.3.3, which gives me these errors:
> > templ_error.cpp: In function ‘int main()’:
> > templ_error.cpp:22: error: multiple parameters named ‘base’
> > templ_error.cpp:23: error: request for member ‘exec’ in ‘test’, which
> > is of non-class type ‘Test<Numeric<3>, Numeric<5> > ()(Numeric<3>,
> > Numeric<5>)’
> > But I can't understand where is the problem: it seems that g++
> > read my declaration of a variable as a function definition.
>
> That's because it is a function declaration.
>
> * * [...]
>
> > int main() {
> > * * int base = 1;
> > * * Test<Numeric<3>, Numeric<5> > test(Numeric<3>(base), Numeric<5> (base));
>
> This declares (not defines) a function taking a Numeric< 3 > and
> a Numeric< 5 > as arguments, and returning a Test< Numeric< 3 >,
> Numeric< 5 > >. *
[snip]
> Note the extra parentheses: C++ syntax doesn't allow the
> declaration of a function parameter to be in parentheses, so the
> results can only be an expression.
>
> The fundamental problem is that "Numeric< 3 >( base )" can be
> parsed as either an expression or a declaration. *In such cases,
> the rules of the language say that if a declaration is legal, it
> is parsed as a declaration. *So you have to do something to
> create a context where a declaration would not be legal.
[snip]
> This is sometimes known as C++'s most embarrassing parse.
> Everyone gets caught out by it from time to time.
And I thought it was the necessary space in nested template

list<vector<int>> -> list<vector<int> >
--
Michael