Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Effective C++: Item 26 (http://www.velocityreviews.com/forums/t952453-effective-c-item-26-a.html)

Bart Vandewoestyne 09-20-2012 03:02 PM

Effective C++: Item 26
 
I am trying to reproduce the ambiguity problem from the first example in Item 26 from Scott Meyers' book 'Effective C++'. My code is online at

https://github.com/BartVandewoestyne..._ambiguity.cpp

In the book, no definition of A's copy constructor nor B's operator A() is given, so i defined it myself... hopefully correct somehow...

Compiling this code with g++ 4.6.2 and the -Wall option succeeds without errors and when I run it, i get:

A(const B&)
f(const A&)

so apparently A's copy constructor gets called and there's no ambiguity problem.

I was suspecting am ambiguity problem at compile time... what am I doing/interpreting wrong?

Regards,
Bart

Victor Bazarov 09-20-2012 06:40 PM

Re: Effective C++: Item 26
 
On 9/20/2012 11:02 AM, Bart Vandewoestyne wrote:
> I am trying to reproduce the ambiguity problem from the first example in Item 26 from Scott Meyers' book 'Effective C++'. My code is online at
>
> https://github.com/BartVandewoestyne..._ambiguity.cpp
>
> In the book, no definition of A's copy constructor nor B's operator A() is given, so i defined it myself... hopefully correct somehow...
>
> Compiling this code with g++ 4.6.2 and the -Wall option succeeds without errors and when I run it, i get:
>
> A(const B&)
> f(const A&)
>
> so apparently A's copy constructor gets called and there's no ambiguity problem.
>
> I was suspecting am ambiguity problem at compile time... what am I doing/interpreting wrong?


Not sure about the compiler you used. Comeau online gives an error
exactly where you expected it.

V
--
I do not respond to top-posted replies, please don't ask

Bart Vandewoestyne 09-20-2012 07:45 PM

Re: Effective C++: Item 26
 
On Thursday, September 20, 2012 8:41:14 PM UTC+2, Victor Bazarov wrote:
>
> Not sure about the compiler you used. Comeau online gives an error
> exactly where you expected it.


I now tested with g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 and everything compiles _without_ any ambiguity error...

Who's wrong here? The book or the compiler?

Regards,
Bart

Victor Bazarov 09-20-2012 10:49 PM

Re: Effective C++: Item 26
 
On 9/20/2012 3:45 PM, Bart Vandewoestyne wrote:
> On Thursday, September 20, 2012 8:41:14 PM UTC+2, Victor Bazarov wrote:
>>
>> Not sure about the compiler you used. Comeau online gives an error
>> exactly where you expected it.

>
> I now tested with g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 and everything compiles _without_ any ambiguity error...
>
> Who's wrong here? The book or the compiler?


I say the g++ compiler is wrong. At least three other compilers (Comeau
online, VC++ 2010, VC++ 2012) report an error...

V
--
I do not respond to top-posted replies, please don't ask

ptyxs 09-21-2012 11:14 AM

Re: Effective C++: Item 26
 
Le 20/09/2012 17:02, Bart Vandewoestyne a écrit :
> I am trying to reproduce the ambiguity problem from the first example in Item 26 from Scott Meyers' book 'Effective C++'. My code is online at
>
> https://github.com/BartVandewoestyne..._ambiguity.cpp
>
> In the book, no definition of A's copy constructor nor B's operator A()is given, so i defined it myself... hopefully correct somehow...
>
> Compiling this code with g++ 4.6.2 and the -Wall option succeeds without errors and when I run it, i get:
>
> A(const B&)
> f(const A&)
>
> so apparently A's copy constructor gets called and there's no ambiguityproblem.
>
> I was suspecting am ambiguity problem at compile time... what am I doing/interpreting wrong?
>
> Regards,
> Bart
>


In my Effective C++ THIRD EDITION, Item 26 is entitled : "Postpone
variable definitions as long as possible".

Please tell what edition you are using and what is the title of the item
you are discussing.
Thanks.
Ptyxs



Nobody 09-21-2012 12:05 PM

Re: Effective C++: Item 26
 
On Fri, 21 Sep 2012 13:14:56 +0200, ptyxs wrote:

> In my Effective C++ THIRD EDITION, Item 26 is entitled : "Postpone
> variable definitions as long as possible".
>
> Please tell what edition you are using and what is the title of the item
> you are discussing.


I'm fairly sure that it's the second edition, where item 26 is titled
"Guard against potential ambiguity".


Richard Delorme 09-21-2012 12:19 PM

Re: Effective C++: Item 26
 
Le 20/09/2012 17:02, Bart Vandewoestyne a écrit :
> I am trying to reproduce the ambiguity problem from the first example in Item 26 from Scott Meyers' book 'Effective C++'. My code is online at
>
> https://github.com/BartVandewoestyne..._ambiguity.cpp
>
> In the book, no definition of A's copy constructor nor B's operator A() is given, so i defined it myself... hopefully correct somehow...
>
> Compiling this code with g++ 4.6.2 and the -Wall option succeeds without errors and when I run it, i get:
>
> A(const B&)
> f(const A&)
>
> so apparently A's copy constructor gets called and there's no ambiguity problem.
>
> I was suspecting am ambiguity problem at compile time... what am I doing/interpreting wrong?


Try to compile your code with the -pedantic options.

--
Richard


Bart Vandewoestyne 09-21-2012 02:47 PM

Re: Effective C++: Item 26
 
On Friday, September 21, 2012 2:05:03 PM UTC+2, Nobody wrote:
>
> I'm fairly sure that it's the second edition, where item 26 is titled
> "Guard against potential ambiguity".


Indeed.

Regards,
Bart

Bart Vandewoestyne 09-21-2012 02:51 PM

Re: Effective C++: Item 26
 
On Friday, September 21, 2012 2:19:52 PM UTC+2, Richard Delorme wrote:
>
> Try to compile your code with the -pedantic options.


Indeed! That gives me the ambiguity error!

Thanks!
Bart

Jorgen Grahn 09-22-2012 08:19 AM

Re: Effective C++: Item 26
 
On Fri, 2012-09-21, Bart Vandewoestyne wrote:
> On Friday, September 21, 2012 2:19:52 PM UTC+2, Richard Delorme wrote:
>>
>> Try to compile your code with the -pedantic options.

>
> Indeed! That gives me the ambiguity error!


I've said it before, but I recommend always using -pedantic (and
several other warning options) with g++. Lots of things which end up
as questions here (often much more trivial than this) would have been
caught that way.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .


All times are GMT. The time now is 02:29 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.