www.digitalmars.com         C & C++   DMDScript  

c++ - non-const reference to temporary

reply Christof Meerwald <cmeerw web.de> writes:
Hi,

this one was recently discussed on comp.lang.c++.moderated (a non-const 
reference shouldn't be allowed to be bound to a temporary):

  #include <stdio.h>

  struct A
  { };

  int f(const A &a)
  {
    printf("f(const A &)\n");
    return 0;
  }

  int f(A &a)
  {
    printf("f(A &)\n");
    return 1;
  }

  int main(int argc, char *argv[])
  {
    return f(A());
  }


But DM calls f(A &) instead of f(const A &).


bye, Christof
Jan 09 2002
parent "Walter" <walter digitalmars.com> writes:
Ok, I've got them logged! -Walter

"Christof Meerwald" <cmeerw web.de> wrote in message
news:a1hu2k$1hkn$2 digitaldaemon.com...
 Hi,

 this one was recently discussed on comp.lang.c++.moderated (a non-const
 reference shouldn't be allowed to be bound to a temporary):

   #include <stdio.h>

   struct A
   { };

   int f(const A &a)
   {
     printf("f(const A &)\n");
     return 0;
   }

   int f(A &a)
   {
     printf("f(A &)\n");
     return 1;
   }

   int main(int argc, char *argv[])
   {
     return f(A());
   }


 But DM calls f(A &) instead of f(const A &).


 bye, Christof

Jan 09 2002