[comp.lang.c++] generic pointer question

ash@pawl.rpi.edu (Arthur Hyun) (04/08/90)

  I'm just learning C and C++, and therefore, this question may seem 
somewhat simplistic, but onwards and forwards regardless:

  I just picked up a copy of _Using C++_, by Bruce Eckel and have come
accross the following:
   [ Chapter 11, page 514 ]
     "In both C++ and ANSI C, you can assign any pointer type to a 
      'void' pointer without using a cast.  In ANSI C, you can also 
      assign a 'void' pointer to a non-'void' pointer without using
      a cast to the non-'void' pointer type.  This is an invitation 
      to errors, and is not allowed in C++."
  With full understanding that the above was not written by 
Bjarne Stroustrup, I would like to ask how, maintaining the spirit 
of polymorphism, one would assign a generic pointer without writting
an overloaded function to encompass all possible datatypes.
  For example, if I were to write a simple stack routine and would like
to be able to have the 'push' routine be able to take ANY datatype, from
unsigned int, to a complex user-defined datatype, the natural thing would
seem to be to 'push' a 'void *datum' onto the stack.  However, one cannot
assign the 'datum' to to the class which is responsible for being the 
stack ("class node_in_stack  { private:  void *info; .... };", for
example) because of the aforementioned.  
  Can anyone help me here?  Thanks in advance...
     --Arthur


-- 
----------------------+-----------------------+-------------------------------
    ash@pawl.rpi.edu  |  sammael@mts.rpi.edu  |  the.arthur@rpitsmts.BITNET
----------------------+-----------------------+-------------------------------