c++ - some_struct* args1 = (some_struct*)args2 -


in c++ code, explain following line doing, have not seen notation before.

some_struct* args1 = (some_struct*)args2 

a simplified example is:

struct some_struct {  myclass1* thisclass1; };  void function1(void *args2) { some_struct* args1 = (some_struct*)args2; //do more stuff } int main(int argc, char* argv) { mainclass1=myclass1::new() some_struct args2; args2.thisclass1=mainclass1; function1((void *)&args2); return 0; } 

forgive grammar, program in python.

in function variable args2 generic pointer, meaning can point can't use directly there no type information associated void. expression (some_struct*)args2 tells compiler pretend args2 pointer some_struct.

this type of expression called cast expression, "casts" 1 type type. syntax c-style cast, inherited in c++ roots in c language.

the c++-specific equivalent of c-style cast reinterpret_cast, like

some_struct* args1 = reinterpret_cast<some_struct*>(args2); 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -