time_period constructor question
Can anyone tell me why the line:
time_period t4(t2);
in the attached cpp file doesn't compile but the line:
time_period t3(t1);
does? it seems like i should be calling the same copy constructor in
both cases but g++ 3.3.4 complains:
error: no matching function for call to `
boost::date_time::period
On Wed, 2005-01-26 at 03:58, Stuart Siegel wrote:
Can anyone tell me why the line:
time_period t4(t2);
in the attached cpp file doesn't compile but the line:
time_period t3(t1);
does? it seems like i should be calling the same copy constructor in both cases but g++ 3.3.4 complains:
The difference between the two lines above is this: time_period t2( ptime(min_date_time), ptime(max_date_time) ); g++ is taking this as a function declaration. (I don't know whether it should be doing so but it is.) Therefore time_period t2 = time_period( ptime(min_date_time), ptime(max_date_time) ); fixes the subsequent problem with time_period t4(t2); N.B. This fix compiles with boost 1.32.0, but not with boost 1.31.0. (g++ 3.3.3) I hope this helps. -- Stephen Jackson
On Wed, 26 Jan 2005 11:08:31 +0000, Stephen Jackson wrote
On Wed, 2005-01-26 at 03:58, Stuart Siegel wrote:
Can anyone tell me why the line:
time_period t4(t2);
in the attached cpp file doesn't compile but the line:
time_period t3(t1);
does? it seems like i should be calling the same copy constructor in both cases but g++ 3.3.4 complains:
The difference between the two lines above is this:
time_period t2( ptime(min_date_time), ptime(max_date_time) );
g++ is taking this as a function declaration. (I don't know whether it should be doing so but it is.) Therefore
Yeah, you are correct it is treating it as a function declaration. This feel like a gcc bug to me, but there could be some obscure reason why it's that way that I'm unaware of. Apparently the use of temporary objects is the what confuses it since time_period t1( tmin, tmax ); works just fine.
N.B. This fix compiles with boost 1.32.0, but not with boost 1.31.0. (g++ 3.3.3)
That's because there was a bug in 1.31 that did not allow ptime to construct special values (constructor was missing). More on the 1.31 to 1.32 changes is documented in: http://www.boost.org/doc/html/date_time/details.html#date_time.changes Jeff
Jeff Garland wrote:
On Wed, 26 Jan 2005 11:08:31 +0000, Stephen Jackson wrote
On Wed, 2005-01-26 at 03:58, Stuart Siegel wrote:
Can anyone tell me why the line:
time_period t4(t2);
in the attached cpp file doesn't compile but the line:
time_period t3(t1);
does? it seems like i should be calling the same copy constructor in both cases but g++ 3.3.4 complains:
The difference between the two lines above is this:
time_period t2( ptime(min_date_time), ptime(max_date_time) );
g++ is taking this as a function declaration. (I don't know whether it should be doing so but it is.) Therefore
Yeah, you are correct it is treating it as a function declaration. This feel like a gcc bug to me, but there could be some obscure reason why it's that way that I'm unaware of. <snip>
This is correct behaviour. The above declaration declares t2 as a function taking two parameters of type ptime (irrelevantly named min_date_time and max_date_time). Any compiler that doesn't parse it as that is broken. Ben.
On Wed, 26 Jan 2005 20:04:57 +0000, Ben Hutchings wrote
Jeff Garland wrote:
Yeah, you are correct it is treating it as a function declaration. This feel like a gcc bug to me, but there could be some obscure reason why it's that way that I'm unaware of. <snip>
This is correct behaviour. The above declaration declares t2 as a function taking two parameters of type ptime (irrelevantly named min_date_time and max_date_time). Any compiler that doesn't parse it as that is broken.
So enlighten me. Why would parenthesis be allowed in the function definition / name? Can't say I've ever seen that syntax used before. What's the advantage -- I can see the downside. Jeff
Jeff Garland wrote:
On Wed, 26 Jan 2005 20:04:57 +0000, Ben Hutchings wrote
Jeff Garland wrote:
Yeah, you are correct it is treating it as a function declaration. This feel like a gcc bug to me, but there could be some obscure reason why it's that way that I'm unaware of.
<snip>
This is correct behaviour. The above declaration declares t2 as a function taking two parameters of type ptime (irrelevantly named min_date_time and max_date_time). Any compiler that doesn't parse it as that is broken.
So enlighten me. Why would parenthesis be allowed in the function definition / name?
Parentheses are sometimes needed in the middle of declarators (example: int (*pf)()), and are allowed even if they are not needed (example: int (i)). That applies even where the names will be ignored, as in the case of parameter names for a non-defining function declaration. This surprising behaviour is sometimes called the "most vexing parse".
Can't say I've ever seen that syntax used before. What's the advantage -- I can see the downside.
I wouldn't argue in favour of it. Ben.
participants (4)
-
Ben Hutchings
-
Jeff Garland
-
Stephen Jackson
-
Stuart Siegel