Re: Compiler chooses conv ctor - why?



Hello,

Charles Wang[MSFT] wrote:
Thank you for your explaining on this according to ISO standard. I think that I understand your meaning. Your main concern should be that at least the compiler should throw an warning to tell developers this potential issue, right? Could you please give Microsoft feedback via https://connect.microsoft.com/visualstudio so that our product team can hear your voice and improve our product? You may also be able to get email notifications when Microsoft product team responds you.

OK - but before, could somebody confirm that in the following code (similar to the code provided by Alex but conv foo is without const qualifier):

======
#include <stdio.h>

struct B;

struct A {
operator B(); /* implicit object parameter: A & */
};

struct B {
B() {}
B(const A&) { printf("conv ctor\n"); }
};

A::operator B()
{
printf("conv foo\n");
return (B());
}

void foo(B) {}

int main()
{
A a;
B b = a; /* 25 */

foo(a); /* 27 */

return 0;
}
======

conversion function should be chosen, as according to 13.3.3.2[3] of the standard, it is better function due to qualification conversion required by conversion constructor (non-const A& to const A&)?

-- best regards

Cezary Noweta
.



Relevant Pages

  • Compiler chooses conv ctor - why?
    ... In the following code conversion from class A object to class B object can be done in two ways: by conversion function being member of class A; by conversion constructor being member of class B. ... This causes that the only implicit conversion sequence goes throughout conversion function. ... A::operator const Bconst ...
    (microsoft.public.vc.language)
  • Re: Why "const rect& rhs" is used here?
    ... declared as const, as far as i can see, i also ... char pcStudentFirstName; ... // Example where struct is copied. ... void SetStudentName ...
    (microsoft.public.vc.language)
  • Re: Cast to a struct?
    ... Neither the source expression nor the target type of a cast is ... allowed to be a struct (except that any expression can be cast to ... A cast specifies a type conversion. ... unsigned int is exactly 32 bits. ...
    (comp.lang.c)
  • Re: simple atomic spscq with static dummy node...
    ... int main ... struct msg_node { ... msg_comm* comm; ... thread* const consumer, ...
    (comp.programming.threads)
  • Re: void* question
    ... Rather than an array of function pointers, ... You should use a struct instead. ... Imagine you had the following in Java: ... double (*const GetValue); ...
    (comp.lang.c)