Reputation: 2097
I am having a blocking trouble trying to figure out what it meant by the following 2 lines. following is a method declaration declared by gsoap and I am confused as to how I should define the parameters for the finstion
SOAP_FMAC3 void SOAP_FMAC4 **soap_serialize_PointerTomss__MobileUserType**(struct soap *soap, mss__MobileUserType *const*a)
So I am trying following but can not figure out what is the error here.
mss__MobileUserType const *mobile_user_type = setupMobileUsertype();
**soap_serialize_PointerTomss__MobileUserType**(soap , &mobile_user_type);
what am I doing wrong here.
Upvotes: 1
Views: 214
Reputation: 5988
Type *const* a;
a
is a pointer
to a const pointer
to Type
.
C++ const
qualifier applies to what is left of it, if there is something on the left, otherwise it applies to what is on the right.
To make simpler consider this.
int a;
int* const p = &a; // (1)
int** pp = &p; // (2) This is not possible since `p` is `const` pointer.
int* const *ppc = &p; // (3) This is your case.
mss__MobileUserType* const mobile_user_type = setupMobileUsertype(); // (1)
mss__MobileUserType* const *mobile_user_type_p = &mobile_user_type; // (3)
soap_serialize_PointerTomss__MobileUserType(soap , mobile_user_type_p);
Read HERE and HERE for more about const correctness.
Upvotes: 5
Reputation: 68638
A declaration can start with a possibly cv-qualfied type-specifier, for example:
X
const X
X const
It can then be followed by zero of more ptr-declarators like:
*
* const
Each one specifies a pointer to the previous type. The const in the ptr-declarator applies to the pointer, not to the type:
For example:
const X*
X const*
X* const
X const * const
X const **const***
Let's break down:
const X ** const*
This is:
const X - const X
* - pointer to previous
* const - const pointer to previous
* - pointer to previous
So it is a "pointer to const pointer to pointer to const X"
Upvotes: 0
Reputation: 153909
The function you are calling expects a pointer to const pointer
to (non-const) mss__MobileUserType
. The expression
&mobile_user_type
is a pointer to (non-const) pointer to const
mss__MobileUserType
. There is no implicit conversion between
the two. (It's also strange to have a pointer to const pointer
to non-const, but I don't know the library, so perhaps there is
a reason. And it's also undefined behavior to have symbols with
two successive underscores.)
Upvotes: 1
Reputation: 283634
Assuming that your declaration is this:
SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_PointerTomss__MobileUserType(struct soap *soap, mss__MobileUserType *const *a);
Then you need to pass the address of a const pointer:
mss__MobileUserType *const mobile_user_type = setupMobileUsertype();
soap_serialize_PointerTomss__MobileUserType(soap , &mobile_user_type);
Upvotes: 0