Topic: Multiple user defined conversion in function return?


Author: Marc Sherman <msherman@mag1.magmacom.com>
Date: 1996/10/16
Raw View
My compiler (Metrowerks CW10) accepts the following code, although
I think it contravenes [class.conv.fct.7] ("At most one user-defined
conversion (constructor or  conversion  function) is implicitly
applied to a single value.")  Is this code in fact illegal, or have
I misunderstood the application of this rule?

 #include <iostream.h>

 class A
 {
 };

 class B
 {
  public:
   B(A /*a*/)
   {
    cout << "Converting A to B" << endl;
   }
 };

 class C
 {
  public:
   C(B /*b*/)
   {
    cout << "Converting B to C" << endl;
   }
 };

 C f();
 C f()
 {
  A a;
  return a;
 }

 int main()
 {
  cout << "ANSI C++ Test app" << endl << endl;

  f();

  return 0;
 }

=== output from running this app ===
ANSI C++ Test app

Converting A to B
Converting B to C

----------------------------------

Doesn't the A returned by function f get converted through two
user defined conversions to a C, illegally?

--
 Marc Sherman |  "What? Rhesus Peasus? | work mailto:marcsh@corel.ca
   CorelDRAW! | Latin. Must be Latin." | personal mailto:msherman@magmacom.com
for Macintosh |  - Edward Ka-Spel, LPD | http://www2.magmacom.com/~msherman/
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]