class class1 {

//variable declaration

};

class class2 {

public:
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.

Recommended Answers

All 2 Replies

The parentheses are used to tell the compiler that the code inside is a typecast, which changes the datatype of variable msg from void* to class1*.

thx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.