-
Dereferencing Pointer
Hi,
I have created a BankID structure with an int and char * parameter.
And, I m trying to access this int and char parameter of this structure.
i have created an instance of this structure as bankID *bankid1;
I am trying to access this as bankid1->pass(which is int!)////
but, i get the error - DEFERENCING POINTER TO AN INCOMPLETE TYPE !!
What does this mean ??
How can i solve this??
Thanks,
-
Have you actually created an instance of the struct to have your pointer variable point to? Just creating a pointer variable to a struct doesn't magically create a struct for you. Where does "bankid1" point to if it is a pointer? Nowhere if don't tell it yourself. If you are going to be using a pointer to the struct, you need to do something like:
Code:
struct bankID *bankid1 = (struct bankID*) malloc(sizeof(struct bankID));
bankid1->pass = 10;
This will actually create a structure dynamically and assign the address of the struct to your pointer variable.
Or, you can forget the pointer and just create an actual struct variable and access the members like so:
Code:
struct bankID bankid1;
bankid1.pass = 10;
Hopefully this should help you out a bit.
-
Hi,
It seems that you have created a pointer to BankID rather than an instance of a BankID.
Try
BankID bankid1;
/*if you need a pointer then add */
BankID *bankidp;
bankidp = &bankid1;
Below is another method.
BankID *bankid1;
bankid1 = (BankID *)malloc(sizeof(BankID));
Hope this helps.
BTW: If you use memory allocation do not forget to free the memory;