   Casting from templated class to char* (C++)
  Is this possible? When I try, I get the errror:'type cast' : cannot convert from 'IdentifiedPacket<Class>' to 'char *'If it is possible, then I will post source code to try to narrow the problem, otherwise, I have to completly re-code some stuff.   
Quote:Original post by PunaProgrammer chrisIs this possible? When I try, I get the errror:'type cast' : cannot convert from 'IdentifiedPacket<Class>' to 'char *'If it is possible, then I will post source code to try to narrow the problem, otherwise, I have to completly re-code some stuff.Youc an easily cast a pointer to another pointer, but casting a non-pointer to a pointer will be harder (which is what you try to do). HTH,   ;  Alright, at least re-programming this will not require much redesign of the program, I can just change some stuff around in one function to end up with the same end product.Thanks once again.   ;  To elaborate a bit, this:Templated<foo> bar;char* baz = reinterpret_cast<char*>(bar);is not the same thing as this:Templated<foo> bar;char* baz = reinterpret_cast<char*>(&bar);The latter is what you want if you want to convert pointer types - from the error you posted, you're trying to convert an object to a pointer via a cast, which is not correct. To get a pointer from an object, you have to take the object's address with the & operator.But in any case this is icky... pointer casts are often a sign of a potentially dangerous design, and almost always mean something is suboptimal. Even if you go with casts, be sure you use C++ casts (static_cast, dynamic_cast and reinterpret_cast primarily) and not C-style casts (which look like (type_b)variable_of_type_a).What specifically are you aiming to do here? I'm guessing this is related to networking somehow? Sounds like what you need is serialization. Note that unless your objects are extremely simple, chances are that just casting to char* and globbing them onto the network will not do what you want.   