Template casting operator

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jonathan Turkanis

    #16
    Re: Template casting operator


    "Jonathan Turkanis" <technews@kanga roologic.com> wrote in message
    news:bvua5m$t9f 91$1@ID-216073.news.uni-berlin.de...[color=blue]
    >
    > "Makhno" <root@127.0.0.1 > wrote in message
    > news:bvu9lt$lk$ 1@newsg4.svr.po l.co.uk...[color=green][color=darkred]
    > > > Did you try using converting constructors instead?[/color]
    > >
    > > Yes, worked straight away. You're right - perhaps I don't need the[/color]
    > cast[color=green]
    > > operator at all.
    > >[color=darkred]
    > > > You probably need a templated assignment operator too, if you do[/color][/color]
    > this.[color=green]
    > >
    > > No, as
    > > Vector<float> pf=pd;
    > > and
    > > Vector<float> pf(pd);
    > > are equivalent;
    > >[/color][/color]
    [color=blue]
    >
    > I didn't suggest a templated assignement operator first because your
    > example didn't require it. But if you want a general-purpose
    > substitute for the conversion operator, you need it.
    >[/color]

    I spoke too soon. It's non needed here either. But it's not because
    of copy initialization.

    Jonathan



    Comment

    • Makhno

      #17
      Re: Template casting operator

      > But that's just one use of the implicit conversion.[color=blue]
      >
      > How about:
      >
      > Vector<double> pd;
      > Vector<float> pf;
      > // More stuff here.
      > pf = pd;
      >
      > ?[/color]

      Hmm, this still seems to work, how peculiar. Vector<> doesn't have an
      assignment operator.


      Comment

      • Makhno

        #18
        Re: Template casting operator

        > I spoke too soon. It's non needed here either. But it's not because[color=blue]
        > of copy initialization.[/color]

        why then?


        Comment

        • Victor Bazarov

          #19
          Re: Template casting operator

          "Jonathan Turkanis" <technews@kanga roologic.com> wrote...[color=blue]
          >
          > "Makhno" <root@127.0.0.1 > wrote in message
          > news:bvu9lt$lk$ 1@newsg4.svr.po l.co.uk...[color=green][color=darkred]
          > > > Did you try using converting constructors instead?[/color]
          > >
          > > Yes, worked straight away. You're right - perhaps I don't need the[/color]
          > cast[color=green]
          > > operator at all.
          > >[color=darkred]
          > > > You probably need a templated assignment operator too, if you do[/color][/color]
          > this.[color=green]
          > >
          > > No, as
          > > Vector<float> pf=pd;
          > > and
          > > Vector<float> pf(pd);
          > > are equivalent;
          > >[/color]
          >
          > But that's just one use of the implicit conversion.
          >
          > How about:
          >
          > Vector<double> pd;
          > Vector<float> pf;
          > // More stuff here.
          > pf = pd;
          >
          > ?
          >
          > I didn't suggest a templated assignement operator first because your
          > example didn't require it. But if you want a general-purpose
          > substitute for the conversion operator, you need it.[/color]

          Why? 'pf = pd' expression will result into the use of compiler-
          generated assignment operator and a construction of a temporary
          on the right side, no? It should be equivalent to

          { Vector<float> temp(pd); pf = temp; }

          No special assignment operator is needed here.

          Correct me if I am wrong.

          V


          Comment

          • Jonathan Turkanis

            #20
            Re: Template casting operator


            "Victor Bazarov" <v.Abazarov@com Acast.net> wrote in message
            news:37yUb.1814 15$Rc4.1339653@ attbi_s54...[color=blue]
            > "Jonathan Turkanis" <technews@kanga roologic.com> wrote...[color=green]
            > >[/color][/color]
            [color=blue]
            > Why? 'pf = pd' expression will result into the use of compiler-
            > generated assignment operator and a construction of a temporary
            > on the right side, no? It should be equivalent to
            >
            > { Vector<float> temp(pd); pf = temp; }
            >
            > No special assignment operator is needed here.
            >
            > Correct me if I am wrong.
            >[/color]

            You're not -- I was :(.

            Jonathan


            Comment

            • Jonathan Turkanis

              #21
              Re: Template casting operator


              "Makhno" <root@127.0.0.1 > wrote in message
              news:bvuak9$253 $1@newsg1.svr.p ol.co.uk...[color=blue][color=green]
              > > I spoke too soon. It's non needed here either. But it's not[/color][/color]
              because[color=blue][color=green]
              > > of copy initialization.[/color]
              >
              > why then?
              >[/color]

              See Victor's post.

              Jonathan


              Comment

              • Victor Bazarov

                #22
                Re: Template casting operator

                "Makhno" <root@127.0.0.1 > wrote...[color=blue][color=green]
                > > But that's just one use of the implicit conversion.
                > >
                > > How about:
                > >
                > > Vector<double> pd;
                > > Vector<float> pf;
                > > // More stuff here.
                > > pf = pd;
                > >
                > > ?[/color]
                >
                > Hmm, this still seems to work, how peculiar. Vector<> doesn't have an
                > assignment operator.[/color]

                Yes, it does. If you don't declare one yourself, the compiler will
                do it for you.


                Comment

                Working...