Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C/C++ is cryptic

Name: Anonymous 2011-08-09 1:16

What does the following C/C++ construction do?

(A->*B)(C,D)[E]

Name: Anonymous 2011-08-09 9:52

Name: Anonymous 2011-08-09 9:55

>>12
Briefly, you're using the pointer as an offset into the class. You can't use this pointers apart from the class they refer to, so:

  int Car::*pSpeed = &Car::speed;
  Car mycar;
  mycar.*pSpeed = 65;

It seems a little obscure, but one possible application is if you're trying to write code for deserializing generic data into many different object types, and your code needs to handle object types that it knows absolutely nothing about (for example, your code is in a library, and the objects into which you deserialize were created by a user of your library). The member pointers give you a generic, semi-legible way of referring to the individual data member offsets, without having to resort to typeless void * tricks the way you might for C structs.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List