[英]Struct member point at another struct member
結構成員是否可以指向來自不同結構的另一個成員? 我想做一些參考表。
struct a {
int a;
int b;
};
struct b {
* struct a.b;
};
猜測是不可能的,因為沒有分配內存,但是我願意提出建議。
當然,只需使用一個指針
struct b
{
int* p ; //or an array of pointers if you need a table
} ;
struct a sa = { 1 , 2 } ;
struct b sb = { &sa.a } ;
printf("%d\n" , sb.p ) ;
sb.p = &sa.b ;
printf("%d\n" , sb.p ) ;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.