Re: visual c++ upgrading problem

Posted by Luigi Ballabio on
URL: http://quantlib.414.s1.nabble.com/visual-c-upgrading-problem-tp3536p3552.html

On 01/24/05 16:13:00, Luca Berardi wrote:

>
> The piece of code:
>
> BoxMullerGaussianRng<MersenneTwisterUniformRng>
>    generator( MersenneTwisterUniformRng() );
> Z = generator.next().value;
>
> generates the following error:
>
> left of '.next' must have class/struct/union type
> type is 'overloaded-function'

Luca,
        you've been bitten by the infamous "C++ most vexing parse." The  
compiler parses the first statement as the declaration of a function called  
'generator' which returns a BoxMuller<MersenneTwister> and takes as  
argument a function with no arguments and returning a MersenneTwister (yes,  
it can be parsed this way. And yes, for some reason the C++ standard  
_requires_ it to be parsed this way. Most vexing indeed.)


> When compiling the same piece of code with Visual C++ 6.0 I didn't get  
> any errors

VC6 didn't follow the C++ standard :)

You can fix the code by rephrasing the variable declaration so that it  
can't be parsed as a function. Something like

MersenneTwisterUniformRng twister;
BoxMullerGaussianRng<MersenneTwisterUniformRng> generator( twister );

should work.

Later,
        Luigi