   Curiosity about type-casting ...
  Okay. I just had a question out of curiosity. For example, when using the "memcpy" function, it takes parameters like "void*" and "const void*". But if you create a pointer to "char" or "int" or something, and you pass it to "memcpy", it works.But my question is this.Should I do:int *pInt  = new int[5];int *pInt2 = new int[5];// Fill 'pInt' array// ...memcpy(pInt2, pInt, sizeof(pInt));Or this:"memcpy((void*) pInt2, (const void*) pInt, sizeof(pInt));"Does it really matter?   
  void * works as a pointer to anything. I'm not exactly sure about this but I believe that the C and C++ standards will say that pointer types may be automatically converted to void *.   ;Quote:Original post by TFS_WaldoDoes it really matter?It shouldn't, since every compiler I know of supports implicit casting to void * - Since that's the real reason why void pointers exist (General memory handling without casting to char pointers).EDIT: Wow, looks like Colin Jeanne beat me.   ;  The latter, i always explicitly cast as well.Dave   ;  I avoid explicitly casting as much as possible.Explicit casts work even when it makes no sense for them to work.Instead, I tend to use:template<typename T>T implicit_cast(T const& t) {return t;}for most of my non-dynamic_cast casting needs.(It is useful for converting between C-types (double to int), and when you want to pass a specific parent class to a function.)The most common exception to implicit cast is:template<typename V>template<typename V>struct void_caster { template<typename T> static void* work(T v) {return v;}};template<typename Void>struct do_cast {  template<typename T> static T work(Void v)  {return reinterpret_cast<T>(v);}};template<> struct void_caster<void*>: do_cast<void*> {};template<> struct void_caster<const void*>: do_cast<const void*> {};  // void cast casts FROM a void TO a different type  // failure to pass in a void will result in a compile errortemplate<typename T, typename V>T void_cast(V v) {return void_caster<V>::work<T>(v);}which makes sure I am casting from a const void* or a void* easy, and prevents you from accidenatally using a C-style/reinterprit cast on a non-void*.Using reinterprit_cast or C-style casting is dangerous.  Because it works when you don't want it to, and when it isn't safe.;  Okay, this leads me to another question. I have seen and read about "dynamic_cast", "static_cast", etc. But I never fully understood them. Can someone give me a (somewhat) detailed explanation about what each does and when the best time to use them is?   ;C++ typecasting.   ;Quote:int *pInt  = new int[5];int *pInt2 = new int[5];// Fill 'pInt' array// ...memcpy(pInt2, pInt, sizeof(pInt));wouldn't sizeof(pInt) return the size of an integer pointer?I think you mean 'sizeof(int) * 5'   