如题,谢谢。

解决方案 »

  1.   

    struct可以定义一个包含多个不同变量的类型,每一个变量在内存中占有自己独立的内存空间,可以同时存储不同类型的数据。
    union也可以定义一个包含多个不同变量类型,但这些变量只共有同一个内存空间,每次只能使用其中的一种变量存储数据。这样 struct中的union规定了这块为共享空间,其余部分为独立空间。
      

  2.   

    #include "stdafx.h"
    #include <iostream>
    #include <string>
    #include <atlstr.h>
    using namespace std;
    struct node{
    union{
    int i;
    CString str1;
    };
    };int main()
    {
    node n;
    node m;
    n.str1="abc";
    n.i=10;
    m.str1="ABC";
    m.i=100;
    cout<<n.str1<<n.i<<endl;
    cout<<m.str1<<m.i<<endl;
    cin>>m.i;
    }为什么程序在VS2005 Debug编译时提示:
    1>.\try.cpp(12) : error C2621: 成员“node::str1”(属于联合“node::<unnamed-tag>”)具有复制构造函数
      

  3.   

    而且有必要在struct内仅包含一个union,那不是直接用union就可以了????
      

  4.   

    struct 还可以包含其它你不想共享内存空间的量啊
      

  5.   

    这我知道,是为了拓展嘛我的意思是如果已经通过编译,不准备再进行拓展了
    如:
    struct node{
        union{
            int i;
            int j;
        };
    };
    是不是可以等价的定义为:
    union node{
        int i;
        int j;
    };
      

  6.   

    定义一个CString类型的对象要包含什么头文件?
      

  7.   

    你怎么定义随便了嘛,要给分的话都给 BUbuWander这个id吧