Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Effective C++: Item 26

Reply
Thread Tools

Effective C++: Item 26

 
 
Bart Vandewoestyne
Guest
Posts: n/a
 
      09-20-2012
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
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      09-20-2012
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
 
Reply With Quote
 
 
 
 
Bart Vandewoestyne
Guest
Posts: n/a
 
      09-20-2012
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
 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      09-20-2012
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
 
Reply With Quote
 
ptyxs
Guest
Posts: n/a
 
      09-21-2012
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


 
Reply With Quote
 
Nobody
Guest
Posts: n/a
 
      09-21-2012
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".

 
Reply With Quote
 
Richard Delorme
Guest
Posts: n/a
 
      09-21-2012
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

 
Reply With Quote
 
Bart Vandewoestyne
Guest
Posts: n/a
 
      09-21-2012
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
 
Reply With Quote
 
Bart Vandewoestyne
Guest
Posts: n/a
 
      09-21-2012
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
 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      09-22-2012
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 .
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
more effective c++ item 31 cfchou@gmail.com C++ 4 09-27-2005 09:15 AM
Effective C++ - item 7 (memory mgt). FBergemann@web.de C++ 1 08-07-2005 12:06 PM
meyers: Item 12: Effective C++ John C++ 4 04-27-2005 04:18 PM
Effective STL Item 4 (size() vs. empty()) Matthias C++ 25 02-01-2005 02:16 PM
Item 13 in Meyer's Effective C++ Don Kim C++ 9 05-23-2004 07:02 PM



Advertisments