Hi all
I've just upgraded from Visual C++ 6.0 to Visual C++ 7.1 (MS .Net). When compiling my own code I could not overcome the problem described below: 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' When compiling the same piece of code with Visual C++ 6.0 I didn't get any errors, (and I can't see why the above code should produce an error, anyway). Can someone please help me fix this problem? Thanks in advance. Luca Berardi __________________________________________________________________ Tiscali Adsl 2 Mega Free, 2 Mega GRATIS! Attiva Tiscali Adsl 2 Mega Free entro il 31 gennaio e navighi GRATIS fino al 31 marzo 2005! In piu', anche il costo di adesione e' GRATIS. Scaricato il concetto? http://abbonati.tiscali.it/adsl/ |
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 |
In reply to this post by Luca Berardi
Hi all,
I am working in VS 2005 beta and I have the
following remarks. Lets take the class FDMDiector with 2
constructors:
FDMDirector { // Default constuctor {m = Mesher(); } FDMDirector ( const Mesher& mesher){// Another constructor m = mesher; } TEST PROGRAM IS NOW
int main(){ using namespace BlackScholesOneFactorIBVP;sigma = mySigma; double d = (sigma)(1.0, 3.9);cout << d << endl; FDMDirector fdir; Vector< double, int> c = fdir.current(); return 0;} NOW, here are some results:
1. If you create a default constructor everything is OK
2. If no default constructor but there is another one, then we get
a compiler error
3. If there are no constructors then compiler generates one
This is exactlly my problem as wel from VC 6. I have not tested VS
2003 (7.1?) but maybe it is same problem.
I notice that the code generates an anonymous object as a
parameter. Maybe ...
Hope this helps,
Luca, if you have any probllems send me a mail.
Ciao e buona serata
Daniel
P.S. other nasty problems have to do with templteas and typedefs; some functions must be inline,eespac iterators in STL From:
[hidden email] on behalf of Luca
Berardi
Sent: Mon 24/01/2005 16:13 To: [hidden email] Subject: [Quantlib-users] visual c++ upgrading problem Hi all |
In reply to this post by Luca Berardi
MersenneTwisterUniformRng
twister;
BoxMullerGaussianRng<MersenneTwisterUniformRng> generator( twister ); I think you must still write the default constructor as well, I
think. In VS 2005 you mustd define def. con.
Hope this helps
Daniel
From:
[hidden email] on behalf of Luigi
Ballabio
Sent: Mon 24/01/2005 16:39 To: Luca Berardi Cc: [hidden email] Subject: Re: [Quantlib-users] visual c++ upgrading problem On 01/24/05 16:13:00, Luca Berardi wrote: |
In reply to this post by Luca Berardi
;; If you want to create a file, first visit that file with C-x C-f, ;; then enter the text in that file's own buffer. Luigi, Daniel thank you very much for your help. Indeed I was not aware of the infamous "C++ most vexing parse" :) Now, following Luigi's suggestion, it works correctly. Regarding Daniel's issue: >NOW, here are some results: > >1. If you create a default constructor everything is OK >2. If no default constructor but there is another one, then we get a compiler >error >3. If there are no constructors then compiler generates one Indeed I noticed the same behavior when playing with my code, trying to get around the problem related to the vexing parse. But I guess it is again related to the issue of the c++ most vexing parse. suppose I write: BoxMullerGaussianRng<MersenneTwisterUniformRng> generator(MersenneTwisterUniformRng() ); Sample<Real> currentSample = generator.next(); The compiler signals an additional error saying that there is no appropriate default constructor. Indeed if you add a default constructor in the Sample<> class this last error disappears, but the preceding one ("error C2228: left of '.next' must have class/struct/union type") still remains. I don't know the hidden reason behind this behavior; unfortunately I'm not a C++ guru, otherwise I should have known of the C++ most vexing parse :) Ciao, grazie Luca __________________________________________________________________ Tiscali Adsl 2 Mega Free, 2 Mega GRATIS! Attiva Tiscali Adsl 2 Mega Free entro il 31 gennaio e navighi GRATIS fino al 31 marzo 2005! In piu', anche il costo di adesione e' GRATIS. Scaricato il concetto? http://abbonati.tiscali.it/adsl/ |
In reply to this post by Luca Berardi
Hi Luca, Luigi,
> C++ most vexing parse :) I am not aware of this problem. 'vexing' is annoying,
yes? I do not seem to have met this problem before but I might yet in the future
if I am lucky:)
Maybe theres is some standard workaround?
Ciao
Daniel
From: Luca Berardi [mailto:[hidden email]] Sent: Mon 24/01/2005 17:50 To: [hidden email]; Daniel J. Duffy; [hidden email] Subject: Re: [Quantlib-users] visual c++ upgrading problem ;; If you want to create a file, first visit that file with C-x
C-f, |
On 01/24/05 17:49:04, Daniel J. Duffy wrote:
> Hi Luca, Luigi, > > > C++ most vexing parse :) > I am not aware of this problem. 'vexing' is annoying, yes? Yes. It came to be known as most annoying since it parses an "obvious" variable declaration such as: Foo foo(Bar()); as the declaration of a function taking a pointer to function, as if it were declared as Foo foo(Bar (*)()); I'm sure the C++ standard committee had a good reason for this, but it escapes me :) > Maybe theres is some standard workaround? The one both you and I suggested---rewriting the above as: Bar bar; Foo foo(bar); Later, Luigi |
In reply to this post by cuchulainn
On 01/24/05 16:54:43, Daniel J. Duffy wrote:
> Hi all, > I am working in VS 2005 beta and I have the following remarks. Lets take > the class FDMDiector with 2 constructors: > > FDMDirector(); > FDMDirector (const Mesher& mesher); > > TEST PROGRAM IS NOW > > int main() > { > > using namespace BlackScholesOneFactorIBVP; > > sigma = mySigma; > > double d = (sigma)(1.0, 3.9); > > cout << d << endl; > > FDMDirector fdir; > > Vector<double, int> c = fdir.current(); > > return 0; > > } > > NOW, here are some results: > > 1. If you create a default constructor everything is OK > 2. If no default constructor but there is another one, then we get a > compiler error > 3. If there are no constructors then compiler generates one Daniel, I'm not sure I understand. What error are we talking about? Later, Luigi |
In reply to this post by Luca Berardi
On 01/24/05 17:50:12, Luca Berardi wrote:
> > ;; If you want to create a file, first visit that file with C-x C-f, > ;; then enter the text in that file's own buffer. Oh, an Emacs user. Nice :) > Regarding Daniel's issue: > > Indeed I noticed the same behavior when playing with my code, trying > to get around the problem related to the vexing parse. But I guess it > is again related to the issue of the c++ most vexing parse. > suppose I write: > > BoxMullerGaussianRng<MersenneTwisterUniformRng> > generator(MersenneTwisterUniformRng() ); > Sample<Real> currentSample = generator.next(); > > The compiler signals an additional error saying that there is no > appropriate default constructor. I'm not sure I'm following. No appropriate default constructor for what? > Indeed if you add a default constructor in the Sample<> class this last > error disappears, but the preceding one ("error C2228: left of '.next' > must have class/struct/union type") still remains. Sample<> doesn't need a default constructor in the lines above---the copy constructor will be called, and that is automatically generated. Does the last error disappear once the vexing parse is fixed? It might be due simply to the compiler going berserk after it can't figure out the call to next... Later, Luigi |
In reply to this post by Luca Berardi
Luigi,
problem is in VS > 6.0 that you MUST
define a default constructor. So if you
generator(MersenneTwisterUniformRng() );
compiler looks for DefCon and does not find it. I think that this was a problem too.
regards Daniel
From: Luigi Ballabio
[mailto:[hidden email]]
Sent: Mon 24/01/2005 18:28 To: Luca Berardi Cc: [hidden email]; Daniel J. Duffy Subject: Re: [Quantlib-users] visual c++ upgrading problem On 01/24/05 17:50:12, Luca Berardi wrote: |
In reply to this post by Luigi Ballabio
>> ;; If you want to create a file, first visit that file with C-x C-f,
>> ;; then enter the text in that file's own buffer. > >Oh, an Emacs user. Nice :) Oops, I forgot to erase it.... >> The compiler signals an additional error saying that there is no >> appropriate default constructor. > >I'm not sure I'm following. No appropriate default constructor for what? for class Sample<T> > Does the >last error disappear once the vexing parse is fixed? It might be due simply >to the compiler going berserk after it can't figure out the call to next... Yes, it does. in my last posting probably I didn't make myself very clear on this point. after having fixed the vexating parse following your suggestion all worked out perfectly. Ciao, Luca __________________________________________________________________ Tiscali Adsl 2 Mega Free, 2 Mega GRATIS! Attiva Tiscali Adsl 2 Mega Free entro il 31 gennaio e navighi GRATIS fino al 31 marzo 2005! In piu', anche il costo di adesione e' GRATIS. Scaricato il concetto? http://abbonati.tiscali.it/adsl/ |
In reply to this post by cuchulainn
On 01/24/05 21:42:52, Daniel J. Duffy wrote:
> problem is in VS > 6.0 that you MUST define a default constructor. So if > you > > generator(MersenneTwisterUniformRng() ); > > compiler looks for DefCon and does not find it. I think that this was a > problem too. Daniel, this is strange, since MersenneTwister _does_ have a default constructor: explicit MersenneTwisterUniformRng(unsigned long seed = 0); Are you saying that in VS > 6, the following won't compile? May you try it? ---------------------------------------- #include <ql/quantlib.hpp> using namespace QuantLib; int main() { MersenneTwisterUniformRng twister; return 0; } ---------------------------------------- Later, Luigi |
In reply to this post by Luca Berardi
Luigi,
I am using 2005 beta, so maybe it is
difernet. All I know is that if you do NOT implement a default constructor my
own code does not work.
I have experienced sttange things when
moving to versions > 6.
regards
Daniel From: Luigi Ballabio [mailto:[hidden email]] Sent: Tue 25/01/2005 09:45 To: Daniel J. Duffy Cc: QuantLib users Subject: Re: [Quantlib-users] visual c++ upgrading problem On 01/24/05 21:42:52, Daniel J. Duffy wrote: |
At 10:25 AM 1/25/2005, Daniel J. Duffy wrote:
>I am using 2005 beta, so maybe it is difernet. All I know is that if you >do NOT implement a default constructor my own code does not work. I've been using the current trunk version of QuantLib with VC 8 (a.k.a. 2005 beta) with no problems at all. QuantLib 0.3.9 will ship with VC8 project files included. The general consensus is that if you turn off the back-compatibility flags (unfortunately on by default) VC 8 is one of the most standard compliant compiler ever available. ciao -- Nando |
In reply to this post by cuchulainn
On 01/25/05 10:25:28, Daniel J. Duffy wrote:
> Luigi, > I am using 2005 beta, so maybe it is difernet. All I know is that if you > do NOT implement a default constructor my own code does not work. Well, if a class doesn't implement a default constructor, your own code cannot call it :) > I have experienced sttange things when moving to versions > 6. VC6 used to let you get away with illegal C++. VC7 and 8 don't. Having said this, I wouldn't exclude that VC8 (being a beta) has issues. However, I still don't have a clear picture of the problem. Is it the Mersenne twister (which _has_ a default constructor) that causes your code to fail? Or is some other class? What exactly is the offending line? Later, Luigi |
In reply to this post by Luca Berardi
Luigi,
It was Luca who had the problems with MT. I
had constructor problems. From: Luigi Ballabio [mailto:[hidden email]] Sent: Tue 25/01/2005 11:43 To: Daniel J. Duffy Cc: QuantLib users Subject: Re: [Quantlib-users] visual c++ upgrading problem On 01/25/05 10:25:28, Daniel J. Duffy wrote: |
On 01/25/05 11:41:58, Daniel J. Duffy wrote:
> It was Luca who had the problems with MT. I had constructor problems. Such as the one you reported? > FDMDirector fdir; > > 1. If you create a default constructor everything is OK > 2. If no default constructor but there is another one, then we get a > compiler error > 3. If there are no constructors then compiler generates one The above is the expected behavior---what is the problem? I apologize for nagging you, but I don't understand whether this is something I should fix in the library or something you should fix in your code... Later, Luigi |
Free forum by Nabble | Edit this page |