void* operations

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ashish.sadanandan@gmail.com

    #1

    void* operations

    Hi,
    I haven't done a lot of C++ programming (done a lot of it in C) and the
    reason why I'm considering switching now is also the question I'm
    posting here.

    I have some library functions that return to me a void* to data that
    has been specifed by the user. There are also functions that return an
    enum which contains information about the data type of this data. So
    what I've done in the past is made a switch case statement based on the
    data type enum and then explicitly re-cast the void* to the appropriate
    data type.

    Now I have a case where I have two values and each of them could be any
    data type. Lets say I have to multiply them. So if I was to use my
    usual method I'd have a switch case statement with numDataType(C)2
    (combination) cases. Does C++ have a better way of extracting data from
    void*?

    Thanks for your help,
    Ashish.

  • Victor Bazarov

    #2
    Re: void* operations

    ashish.sadanand an@gmail.com wrote:[color=blue]
    > I haven't done a lot of C++ programming (done a lot of it in C) and
    > the reason why I'm considering switching now is also the question I'm
    > posting here.
    >
    > I have some library functions that return to me a void* to data that
    > has been specifed by the user. There are also functions that return an
    > enum which contains information about the data type of this data. So
    > what I've done in the past is made a switch case statement based on
    > the data type enum and then explicitly re-cast the void* to the
    > appropriate data type.
    >
    > Now I have a case where I have two values and each of them could be
    > any data type. Lets say I have to multiply them. So if I was to use my
    > usual method I'd have a switch case statement with numDataType(C)2
    > (combination) cases. Does C++ have a better way of extracting data
    > from void*?[/color]

    "Better" in what sense?

    V
    --
    Please remove capital As from my address when replying by mail


    Comment

    • Ian Collins

      #3
      Re: void* operations

      ashish.sadanand an@gmail.com wrote:[color=blue]
      > Hi,
      > I haven't done a lot of C++ programming (done a lot of it in C) and the
      > reason why I'm considering switching now is also the question I'm
      > posting here.
      >
      > I have some library functions that return to me a void* to data that
      > has been specifed by the user. There are also functions that return an
      > enum which contains information about the data type of this data. So
      > what I've done in the past is made a switch case statement based on the
      > data type enum and then explicitly re-cast the void* to the appropriate
      > data type.
      >
      > Now I have a case where I have two values and each of them could be any
      > data type. Lets say I have to multiply them. So if I was to use my
      > usual method I'd have a switch case statement with numDataType(C)2
      > (combination) cases. Does C++ have a better way of extracting data from
      > void*?
      >[/color]
      Yes, don't!

      Return a pointer to a base type and derive all your data classes from
      it. A case of refactoring from switch to polymorphism.

      class Base
      {
      virtual ~base() {}
      ...
      };

      class Data1 : public Base
      {
      ....
      };

      ....

      --
      Ian Collins.

      Comment

      • Praetorian

        #4
        Re: void* operations


        Victor Bazarov wrote:[color=blue]
        > ashish.sadanand an@gmail.com wrote:[color=green]
        > > I haven't done a lot of C++ programming (done a lot of it in C) and
        > > the reason why I'm considering switching now is also the question I'm
        > > posting here.
        > >
        > > I have some library functions that return to me a void* to data that
        > > has been specifed by the user. There are also functions that return an
        > > enum which contains information about the data type of this data. So
        > > what I've done in the past is made a switch case statement based on
        > > the data type enum and then explicitly re-cast the void* to the
        > > appropriate data type.
        > >
        > > Now I have a case where I have two values and each of them could be
        > > any data type. Lets say I have to multiply them. So if I was to use my
        > > usual method I'd have a switch case statement with numDataType(C)2
        > > (combination) cases. Does C++ have a better way of extracting data
        > > from void*?[/color]
        >
        > "Better" in what sense?
        >
        > V
        > --
        > Please remove capital As from my address when replying by mail[/color]

        Victor, "better way" in the sense that will it be possible for me to
        define some sort of template or something else that will alow me to
        have a common function that can be called with a void* irrespective of
        the data type of the data that the pointer actually points to.

        Ashish.

        Comment

        • Praetorian

          #5
          Re: void* operations


          Ian Collins wrote:[color=blue]
          > ashish.sadanand an@gmail.com wrote:[color=green]
          > > Hi,
          > > I haven't done a lot of C++ programming (done a lot of it in C) and the
          > > reason why I'm considering switching now is also the question I'm
          > > posting here.
          > >
          > > I have some library functions that return to me a void* to data that
          > > has been specifed by the user. There are also functions that return an
          > > enum which contains information about the data type of this data. So
          > > what I've done in the past is made a switch case statement based on the
          > > data type enum and then explicitly re-cast the void* to the appropriate
          > > data type.
          > >
          > > Now I have a case where I have two values and each of them could be any
          > > data type. Lets say I have to multiply them. So if I was to use my
          > > usual method I'd have a switch case statement with numDataType(C)2
          > > (combination) cases. Does C++ have a better way of extracting data from
          > > void*?
          > >[/color]
          > Yes, don't!
          >
          > Return a pointer to a base type and derive all your data classes from
          > it. A case of refactoring from switch to polymorphism.
          >
          > class Base
          > {
          > virtual ~base() {}
          > ...
          > };
          >
          > class Data1 : public Base
          > {
          > ...
          > };
          >
          > ...
          >
          > --
          > Ian Collins.[/color]

          I'm sorry Ian but I have no idea what you just said, as I mentioned
          before I don't have much C++ knowledge. Could you please elaborate a
          little more? And maybe suggest some of the things I should be reading
          up to do this; virtual seems to be something I should learn more about.

          Thanks,
          Ashish

          Comment

          • red floyd

            #6
            Re: void* operations

            Praetorian wrote:[color=blue]
            > [redacted]
            >
            > I'm sorry Ian but I have no idea what you just said, as I mentioned
            > before I don't have much C++ knowledge. Could you please elaborate a
            > little more? And maybe suggest some of the things I should be reading
            > up to do this; virtual seems to be something I should learn more about.[/color]


            The canonical example is a drawing program with shapes.

            class Shape {
            public:
            virtual void Draw();
            // other methods redacted
            };

            class Circle : public Shape {
            public:
            void Draw();
            // other methods redacted
            };

            class Rectangle : public Shape {
            public:
            void Draw();
            // other methods redacted
            };

            Now, you can just keep track of Shape*'s. Since you're not familiar
            with C++, I'll use an array (yes, C++ people, I know he should use a
            vector, and yes, I know there's likely memory leaks in the sample).

            Shape* shapes[NSHAPES];

            // reads shapes from a file.
            int ReadShapes(Shap e* shapelist[], int max_shapes);

            int main()
            {
            int n = ReadShapes(shap es, NSHAPES);

            for (int i = 0; i < n ; ++i)
            shapes[i]->Draw();
            }

            In this example, you don't have to worry about what kind of shape each
            element of the array "shapes" is. Each element "knows" what kind of
            data it is and does the right thing when asked to draw itself.

            That's a very simplified example of polymorphism. Shape is the base
            class, and Circle and Rectangle are derived classes. That's what Ian
            was talking about. Instead of returning void* and having a switch
            statement from hell, you create a class hierarchy with virtual
            functions, return a pointer (or a reference) to the base class, and call
            the virtual function, which "knows what to do".

            I highly recommend getting "Accelerate d C++" by Koenig and Moo.

            Comment

            • benben

              #7
              Re: void* operations

              > I'm sorry Ian but I have no idea what you just said, as I mentioned[color=blue]
              > before I don't have much C++ knowledge. Could you please elaborate a
              > little more? And maybe suggest some of the things I should be reading
              > up to do this; virtual seems to be something I should learn more about.
              >
              > Thanks,
              > Ashish
              >[/color]

              Let's say you have a bunch of methods of transportation represented as
              types (e.g. bus, taxi, train, car, tram, etc) and despite all the
              differences in between, all of them can be started and stopped.

              What C++ allows you to do, is to start and/or stop any type of
              transportation without knowing which type it is. What you do is you put
              functions start and stop in a base class and derive all other
              transportation from that class:

              class transport
              {
              public:
              virtual void start(void) = 0;
              virtual void stop (void) = 0;

              virtual ~transport(); // destructor
              };

              class bus: public transport
              {
              public:
              void start(void)
              {
              signal_passenge rs();
              close_the_doors ();
              log_timetable() ;
              ignite_engine() ;
              // ...
              }

              void stop(void)
              {
              apply_brake();
              open_the_doors( );
              wait_for_passen gers_to_get_off ();
              log_time_table( );
              switch_off_engi ne();
              }

              // also a bunch of bus-specific features...
              };

              class taxi: public transport
              {
              public:
              void start(void)
              {
              start_mile_coun ter();
              say_hello_to_pa ssenger();
              ask_for_destina tion();
              off_you_go();
              }

              void stop(void)
              {
              apply_brake();
              get_paid();
              say_goodbye();
              }

              // also a bunc of taxi-specific features...
              };

              Now a bus* pointer is also a transport* pointer; a taxi* is also a
              transport*; etc. So you can do someting like:

              int main()
              {
              transport* t;
              taxi my_favorite;
              bux my_second_favor ite;

              t = &my_favorite ;
              t->start(); // starts a taxi
              t->stop(); // stops a taxi

              t = &my_second_favo rite;
              t->start(); // starts a bus
              t->stop(); // stops a bus
              }

              Well, if you have no clue what I am talking about I strongly recommend
              you to grab a C++ book and read on classes and derived classes.

              Regards,
              Ben

              Comment

              • Ian Collins

                #8
                Re: void* operations

                Praetorian wrote:[color=blue]
                >
                > I'm sorry Ian but I have no idea what you just said, as I mentioned
                > before I don't have much C++ knowledge. Could you please elaborate a
                > little more? And maybe suggest some of the things I should be reading
                > up to do this; virtual seems to be something I should learn more about.
                >[/color]
                Oh dear, you should get yourself a couple of decent C++ books,
                "Accelerate d C++" and "The C++ programming language, 3rd edition" are a
                good start.

                A very common way to replace C style switches is to use polymorphic
                types and virtual methods. You must understand these concepts, a simple
                google for "polymorphi c virtual C++" should get you started.

                Welcome to the fun world of C++.

                --
                Ian Collins.

                Comment

                • Victor Bazarov

                  #9
                  Re: void* operations

                  Praetorian wrote:[color=blue]
                  > Victor Bazarov wrote:[color=green]
                  >> ashish.sadanand an@gmail.com wrote:[color=darkred]
                  >>> I haven't done a lot of C++ programming (done a lot of it in C) and
                  >>> the reason why I'm considering switching now is also the question
                  >>> I'm posting here.
                  >>>
                  >>> I have some library functions that return to me a void* to data that
                  >>> has been specifed by the user. There are also functions that return
                  >>> an enum which contains information about the data type of this
                  >>> data. So what I've done in the past is made a switch case statement
                  >>> based on the data type enum and then explicitly re-cast the void*
                  >>> to the appropriate data type.
                  >>>
                  >>> Now I have a case where I have two values and each of them could be
                  >>> any data type. Lets say I have to multiply them. So if I was to use
                  >>> my usual method I'd have a switch case statement with
                  >>> numDataType(C)2 (combination) cases. Does C++ have a better way of
                  >>> extracting data from void*?[/color]
                  >>
                  >> "Better" in what sense?
                  >>
                  >> V
                  >> --
                  >> Please remove capital As from my address when replying by mail[/color]
                  >
                  > Victor, "better way" in the sense that will it be possible for me to
                  > define some sort of template or something else that will alow me to
                  > have a common function that can be called with a void* irrespective of
                  > the data type of the data that the pointer actually points to.[/color]

                  Apparently, your 'void*' only designates the address of some memory
                  area. If the object that occupies that memory has been successfully
                  constructed by those "library functions", then you can simply _cast_
                  the pointer to the pointer to the type as indicated by that enum.
                  You can use 'static_cast'.

                  If your memory area does _not_ contain a successfully constructed object,
                  then the cast doesn't help. However, you probably know the layout of
                  the memory, so you can easily write the algorithm of "recreating " the
                  objects. I strongly recommend letting the objects construct themselves
                  by having properly defined _explicit_ constructors to which you will
                  pass the void*.

                  Having re-read your post, I am still unable to understand what it is
                  you do not like about "recasting" as you put it. If you're stuck with
                  those library functions, there is no simpler or more straightforward
                  way.

                  V
                  --
                  Please remove capital As from my address when replying by mail


                  Comment

                  • Praetorian

                    #10
                    Re: void* operations


                    Victor Bazarov wrote:[color=blue]
                    > Praetorian wrote:[color=green]
                    > > Victor Bazarov wrote:[color=darkred]
                    > >> ashish.sadanand an@gmail.com wrote:
                    > >>> I haven't done a lot of C++ programming (done a lot of it in C) and
                    > >>> the reason why I'm considering switching now is also the question
                    > >>> I'm posting here.
                    > >>>
                    > >>> I have some library functions that return to me a void* to data that
                    > >>> has been specifed by the user. There are also functions that return
                    > >>> an enum which contains information about the data type of this
                    > >>> data. So what I've done in the past is made a switch case statement
                    > >>> based on the data type enum and then explicitly re-cast the void*
                    > >>> to the appropriate data type.
                    > >>>
                    > >>> Now I have a case where I have two values and each of them could be
                    > >>> any data type. Lets say I have to multiply them. So if I was to use
                    > >>> my usual method I'd have a switch case statement with
                    > >>> numDataType(C)2 (combination) cases. Does C++ have a better way of
                    > >>> extracting data from void*?
                    > >>
                    > >> "Better" in what sense?
                    > >>
                    > >> V
                    > >> --
                    > >> Please remove capital As from my address when replying by mail[/color]
                    > >
                    > > Victor, "better way" in the sense that will it be possible for me to
                    > > define some sort of template or something else that will alow me to
                    > > have a common function that can be called with a void* irrespective of
                    > > the data type of the data that the pointer actually points to.[/color]
                    >
                    > Apparently, your 'void*' only designates the address of some memory
                    > area. If the object that occupies that memory has been successfully
                    > constructed by those "library functions", then you can simply _cast_
                    > the pointer to the pointer to the type as indicated by that enum.
                    > You can use 'static_cast'.
                    >
                    > If your memory area does _not_ contain a successfully constructed object,
                    > then the cast doesn't help. However, you probably know the layout of
                    > the memory, so you can easily write the algorithm of "recreating " the
                    > objects. I strongly recommend letting the objects construct themselves
                    > by having properly defined _explicit_ constructors to which you will
                    > pass the void*.
                    >
                    > Having re-read your post, I am still unable to understand what it is
                    > you do not like about "recasting" as you put it. If you're stuck with
                    > those library functions, there is no simpler or more straightforward
                    > way.
                    >
                    > V
                    > --
                    > Please remove capital As from my address when replying by mail[/color]

                    Thank you for all of your replies; and I have been busy Google searches
                    for C++ tutorials since my last post; in fact I was just about to read
                    about virtual functions when I decided to check this posting again.

                    Victor, the void* returned to me does point to a successfully
                    constructed object in memory, having the size of whatever the data type
                    enum; I can simply re-cast to the data type pointer and access it
                    without worrying about any kind of memory corruption (thank God for
                    that). Let me try and illustrate my problem with explicit casting using
                    an example:

                    Let's say I have 2 values that I need to multiply and each value may be
                    an int16 or an int32. I have void pointers v1 and v2 to each. So the
                    way I see what I need to do is something like:

                    if(d1 == INT16 && d2 == INT16)
                    {
                    v1int16 = (int16 *)v1;
                    v2int16 = (int16 *)v2;
                    output = v1*v2;
                    }
                    else if(d1 == INT16 && d2 == INT32)
                    {
                    v1int16 = (int16 *)v1;
                    v2int32 = (int32 *)v2;
                    output = v1*v2;
                    }
                    else if(d1 == INT32 && d2 == INT16)
                    { .....}
                    else
                    {......}

                    Now this becomes rather tedious because I need to support 10 different
                    data types and I have to operate on 3 values instead of 2; basically a
                    switch case or if else construct from hell as someone put it in an
                    earlier post.

                    Although the virtual function method looks promising doesn't that still
                    mean I need to have a function for each combination of data types? I
                    was looking into templates but even with them the problem is that my
                    knowledge of the data type lies in an enum value and I don't know how
                    to incorporate this in a template; maybe a template which does the
                    final operation on pointers and virtual functions to 'condition' the
                    values based on their data types, if any conditioning is needed. These
                    functions would return pointers that can be used by the template.

                    I'm just throwing out ideas here and forgive me if I've managed to
                    sound stupid with my solution. You guys should be able to suggest
                    something that works for me.

                    Thanks,
                    Ashish.

                    Comment

                    • Victor Bazarov

                      #11
                      Re: void* operations

                      Praetorian wrote:[color=blue]
                      > [..]
                      > Victor, the void* returned to me does point to a successfully
                      > constructed object in memory, having the size of whatever the data
                      > type enum; I can simply re-cast to the data type pointer and access it
                      > without worrying about any kind of memory corruption (thank God for
                      > that). Let me try and illustrate my problem with explicit casting
                      > using an example:
                      >
                      > Let's say I have 2 values that I need to multiply and each value may
                      > be an int16 or an int32. I have void pointers v1 and v2 to each. So
                      > the way I see what I need to do is something like:
                      >
                      > if(d1 == INT16 && d2 == INT16)
                      > {
                      > v1int16 = (int16 *)v1;
                      > v2int16 = (int16 *)v2;[/color]

                      You probably meant

                      v1int16 = *(int16*)v1;

                      and so on...
                      [color=blue]
                      > output = v1*v2;[/color]

                      What type is 'output'?
                      [color=blue]
                      > }
                      > else if(d1 == INT16 && d2 == INT32)
                      > {
                      > v1int16 = (int16 *)v1;
                      > v2int32 = (int32 *)v2;
                      > output = v1*v2;
                      > }
                      > else if(d1 == INT32 && d2 == INT16)
                      > { .....}
                      > else
                      > {......}
                      >
                      > Now this becomes rather tedious because I need to support 10 different
                      > data types and I have to operate on 3 values instead of 2; basically a
                      > switch case or if else construct from hell as someone put it in an
                      > earlier post.
                      >
                      > Although the virtual function method looks promising doesn't that
                      > still mean I need to have a function for each combination of data
                      > types?[/color]

                      You bet.
                      [color=blue]
                      > I was looking into templates but even with them the problem is
                      > that my knowledge of the data type lies in an enum value and I don't
                      > know how to incorporate this in a template; maybe a template which
                      > does the final operation on pointers and virtual functions to
                      > 'condition' the values based on their data types, if any conditioning
                      > is needed. These functions would return pointers that can be used by
                      > the template.[/color]

                      Templates are not going to help you since your types are not known
                      until run-time. Still, even then they are not true C++ types in the
                      run-time sense (polymorphic types). They are just chunks of memory
                      whose meaning is expressed in some other values. Even though they
                      have been constructed, to use them you need to provide some switch
                      statement, there is no escaping that.

                      Now, you _could_ define your base class for your operations and then
                      derive your 10 types from it. Then all the operations just need to
                      be implemented as a case of double dispatch (look it up).

                      An alternative would be to extract those values into another type,
                      some kind of common denominator. If they are all integrals, use
                      'long' or 'unsigned long' to represent the values. If that's not
                      enough, use implementation-specific larger value (like 'int64_t' in
                      Visual C++, for example).
                      [color=blue]
                      > I'm just throwing out ideas here and forgive me if I've managed to
                      > sound stupid with my solution. You guys should be able to suggest
                      > something that works for me.[/color]

                      Hey, at the end of the day, we're not going to solve your problem.
                      You have to do it yourself. Bite the bullet and just code all those
                      1000 possibilities.

                      V
                      --
                      Please remove capital As from my address when replying by mail


                      Comment

                      • Praetorian

                        #12
                        Re: void* operations


                        Victor Bazarov wrote:[color=blue]
                        > Praetorian wrote:[color=green]
                        > > [..]
                        > > Victor, the void* returned to me does point to a successfully
                        > > constructed object in memory, having the size of whatever the data
                        > > type enum; I can simply re-cast to the data type pointer and access it
                        > > without worrying about any kind of memory corruption (thank God for
                        > > that). Let me try and illustrate my problem with explicit casting
                        > > using an example:
                        > >
                        > > Let's say I have 2 values that I need to multiply and each value may
                        > > be an int16 or an int32. I have void pointers v1 and v2 to each. So
                        > > the way I see what I need to do is something like:
                        > >
                        > > if(d1 == INT16 && d2 == INT16)
                        > > {
                        > > v1int16 = (int16 *)v1;
                        > > v2int16 = (int16 *)v2;[/color]
                        >
                        > You probably meant
                        >
                        > v1int16 = *(int16*)v1;
                        >
                        > and so on...
                        >[color=green]
                        > > output = v1*v2;[/color]
                        >
                        > What type is 'output'?
                        >[color=green]
                        > > }
                        > > else if(d1 == INT16 && d2 == INT32)
                        > > {
                        > > v1int16 = (int16 *)v1;
                        > > v2int32 = (int32 *)v2;
                        > > output = v1*v2;
                        > > }
                        > > else if(d1 == INT32 && d2 == INT16)
                        > > { .....}
                        > > else
                        > > {......}
                        > >
                        > > Now this becomes rather tedious because I need to support 10 different
                        > > data types and I have to operate on 3 values instead of 2; basically a
                        > > switch case or if else construct from hell as someone put it in an
                        > > earlier post.
                        > >
                        > > Although the virtual function method looks promising doesn't that
                        > > still mean I need to have a function for each combination of data
                        > > types?[/color]
                        >
                        > You bet.
                        >[color=green]
                        > > I was looking into templates but even with them the problem is
                        > > that my knowledge of the data type lies in an enum value and I don't
                        > > know how to incorporate this in a template; maybe a template which
                        > > does the final operation on pointers and virtual functions to
                        > > 'condition' the values based on their data types, if any conditioning
                        > > is needed. These functions would return pointers that can be used by
                        > > the template.[/color]
                        >
                        > Templates are not going to help you since your types are not known
                        > until run-time. Still, even then they are not true C++ types in the
                        > run-time sense (polymorphic types). They are just chunks of memory
                        > whose meaning is expressed in some other values. Even though they
                        > have been constructed, to use them you need to provide some switch
                        > statement, there is no escaping that.
                        >
                        > Now, you _could_ define your base class for your operations and then
                        > derive your 10 types from it. Then all the operations just need to
                        > be implemented as a case of double dispatch (look it up).
                        >
                        > An alternative would be to extract those values into another type,
                        > some kind of common denominator. If they are all integrals, use
                        > 'long' or 'unsigned long' to represent the values. If that's not
                        > enough, use implementation-specific larger value (like 'int64_t' in
                        > Visual C++, for example).
                        >[color=green]
                        > > I'm just throwing out ideas here and forgive me if I've managed to
                        > > sound stupid with my solution. You guys should be able to suggest
                        > > something that works for me.[/color]
                        >
                        > Hey, at the end of the day, we're not going to solve your problem.
                        > You have to do it yourself. Bite the bullet and just code all those
                        > 1000 possibilities.
                        >
                        > V
                        > --
                        > Please remove capital As from my address when replying by mail[/color]



                        Victor, sorry about the typos earlier but you interpreted them
                        correctly. Output data type is my third variable data type. I'm using
                        this in a block that will be used in Simulink simulations and all 3
                        data types will be specified by the user on the block dialog. The
                        functions that return the void* to me are Simulink callback methods
                        which are called at every time step to calculate the output of the
                        block. Simulink doesn't support 64-bit data types and anyway, I don't
                        want to go down that path because I do actually want to do what the
                        user is asking me to do. For instance if the user gives me data sets
                        which will result in an overflow I want there to be an overflow; which
                        may be hard to reproduce if I up-cast the data.

                        I just read the definition of double dispatch and it says that it is
                        used in cases where data types of arguments are only know at run time;
                        sounds like it is exactly what I need. But I should first look into
                        some of the more basic aspects of C++ like polymorphism and inheritance
                        before I jump into that. In the meanwhile could you tell me if you
                        think it's possible to solve my problem using double dispatch. Because
                        if not and I'm going to have to code 1000 switch case statements then
                        I'm going back to C :-)

                        Comment

                        • Victor Bazarov

                          #13
                          Re: void* operations

                          Praetorian wrote:[color=blue]
                          > [...]
                          > I just read the definition of double dispatch and it says that it is
                          > used in cases where data types of arguments are only know at run time;
                          > sounds like it is exactly what I need. But I should first look into
                          > some of the more basic aspects of C++ like polymorphism and
                          > inheritance before I jump into that. In the meanwhile could you tell
                          > me if you think it's possible to solve my problem using double
                          > dispatch. Because if not and I'm going to have to code 1000 switch
                          > case statements then I'm going back to C :-)[/color]

                          Look, if I were to give any weight to my answer about the possibility
                          to solve your problem with double dispatch, I'd have to basically solve
                          it an I have neither the time, nor the energy. And you're right, it
                          would require you to learn inheritance and polymorphism.

                          As to going back to C, good luck, but I think you'd still need to write
                          your 1000 switch case statements there just as well.

                          V
                          --
                          Please remove capital As from my address when replying by mail


                          Comment

                          • persenaama

                            #14
                            Re: void* operations

                            What will this code be used for? Please don't say: "to multiply scalars
                            of different type together", something more higher level information
                            about the intended use would come in handy when factoring an useful
                            answer.. :)

                            Comment

                            • Praetorian

                              #15
                              Re: void* operations


                              persenaama wrote:[color=blue]
                              > What will this code be used for? Please don't say: "to multiply scalars
                              > of different type together", something more higher level information
                              > about the intended use would come in handy when factoring an useful
                              > answer.. :)[/color]

                              In this case it is something as mundane as multiplying 2-3 numbers
                              together after converting them to the data types that the user has
                              specified.

                              Comment

                              Working...