typedef struct pjmedia_endpt pjmedia_endpt;
declaration of struct pjmedia_endpt endpt and pjmedia_endpt endpt are no ok("Variable has incomplete type struct pjmedia_endpt endpt").
i want to declare a variable of pjmedia_endpt, how to do.
Until unless you complete the incomplete type like this,
struct pjmedia_endpt
{
member1;
member2;
...
};
you can not use pjmedia_endpt
.
Once you complete the structure, then you can use
pjmedia_endpt temp; // Declare a variable to it
Your typedef
establishes a forward declaration. After this forward declaration you can define variables of type "pointer to pjmedia_endpt
", like this:
pjmedia_endpt *ptrVar;
However, forward declaration by itself is not enough to declare variables or struct
fields until the actual definition is provided. You need to define the actual structure of pjmedia_endpt
before you could start using your newly defied type pjmedia_endpt
for variable declarations:
struct pjmedia_endpt {
...
};
You must use typedef
to define a new type based on a predefined structure or a type. Otherwise you cannot declare a variable with that new type unless you define the pjmedia_endpt structure.
First define your structure:
struct pjmedia_endpt{
// ...
};
Then you can assigne a type name to your structure:
typedef struct pjmedia_endpt pjmedia_endpt;
Then you can declare a variable with the new type:
pjmedia_endpt someVariable;
here is a function need pjmedia_endpt. pjmedia_transport_udp_create(pjmedia_endpt* endpt,...);
actually i what i need is a pointer,so instead
//declare a pointer.
pjmedia_endpt* endpt;
//do init endpt.then pass pointer to the function.
pjmedia_transport_udp_create(endpt,...);
typedef struct pjmedia_endpt{
// ...
};
// Now Rename the structure
pjmedia_endpt newname;
// And now you can access the member of structure with newname.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.