Class pointer.

class class1 {

//variable declaration


class class2 {

int func(void *msg);
// others func...


int class2::func(void *msg)

class1 *pointer = (class1 *)msg;
//others declaration.

I would like to ask reagrding on this line of code :
class1 *pointer = (class1 *)msg;
the class declaring a pointer to be equal with "(class1 *)msg"

My question is the parenthesis is for? as the msg is already declared as pointer based on the "int func(void *msg)" so is it the parenthesis is to avoid another declare of pointer in msg? as i know there is no such pointer declare or class pointer declare where by the astrik(*) is behind the variable eg: p*

hope you guys can explain to be the line of code..

thank you in advance.
It's a cast. It changes one type (void *) to another (class1 *) which may be dangerous if the passed parameter is not the expected type
Topic archived. No new replies allowed.