c、c++ 結構體的嵌套,結構體嵌套

來源:互聯網
上載者:User

c、c++ 結構體的嵌套,結構體嵌套
c、c++ 結構體的嵌套

/************************************************************************//* 嵌套結構體                                                                     * C++ **//************************************************************************/struct A {private:int a1[20];public:void initialize();struct B {private:A *b;int *p;public:void initialize(A *a);void next();int read;void set(int i);};friend A::B;};void A::initialize(){memset(a1, 0, sizeof(a1));}void A::B::initialize(A *a){b = a;p = a->a1;}void A::B::set(int i){*p = i;}/*void main(){A a;A::B b1,b2;int i;a.initialize();b1.initialize(&a);b2.initialize(&a);for (i =0; i<20; i++){b1.set(i);b2.set(i);}}/************************************************************************//* C * 嵌套結構體 *  * *//************************************************************************/ typedef struct A{int year;int month;int day;};typedef struct B {string name;int age;union{A aa;}xy;struct A aa1;};void main(){B *b1 =NULL;b1->xy.aa.day =1991;b1->aa1.month = 7;getchar();}



教各位大俠,c語言結構體嵌套的問題、

C語言實現不了你的想法。結構本身是沒有值的,只有結構成員才有值。

typedef struct{
float H;
float L;
float actual;
}physic;

typedef struct{
physic v;
physic p;
}thing;
thing RTU;
RTU.v.H=123.456;
RTU.v.L=0;
RTU.v.actual=100;
 
C語言中結構體嵌套後怎放到函數體中

以形參的形式放入函數體進行操作,只需要將形參和實參類型匹配就可以了。比如a[i].riqi.year是int型,那麼你的函數就可以寫成void fun(int i)。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.