Possible Duplicate:
What does a colon following a C++ constructor name do?
I'm reading a book about CUDA & I'm having trouble reading this C++ syntax. I'm not sure what to search for so that's why I'm posting here.
struct cuComplex {
float r;
float i;
cuComplex( float a, float b ) : r(a) , i(b) {}
}
What does the cuComplex statement do? Specifically:
cuComplex( float a, float b ) : r(a) , i(b) {}
what is this called so I can learn about it?
That is C++, not C, as C structs cannot contain functions in that manner (they could contain a function pointer, but that is irrelevant to the question). That is a constructor for the type "cuComplex" that takes two floats. It initializes the two member variables 'r' and 'r' with the passed in values.
EDIT per comment: The r(a) and i(b) parts are initializing the member variables with the values of the parameters to the constructor.