struct TestUnion
{
TestUnion() {}
};
typedef union
{
TestUnion obj;
} UT;
int main (void)
{
return 0;
}
class TestUnion
{
union DataUnion
{
DataUnion(const char*);
DataUnion(long);
const char* ch_;
long l_;
} data_;
public:
TestUnion(const char* ch);
TestUnion(long l);
};
TestUnion::TestUnion(const char* ch) : data_(ch) // if you want to use initialzing list to initiate a nested-union member, the union must not be anonymous and must have a constructor。
{}
TestUnion::TestUnion(long l) : data_(l)
{}
TestUnion::DataUnion::DataUnion(const char* ch) : ch_(ch)
{}
TestUnion::DataUnion::DataUnion(long l) : l_(l)
{}
int main (void)
{
return 0;
}
class TestUnion
{
union DataUnion
{
const char* ch_;
long l_;
} data_;
public:
TestUnion(const char* ch);
TestUnion(long l);
};
TestUnion::TestUnion(const char* ch)
{
data_.ch_ = ch;
}
TestUnion::TestUnion(long l)
{
data_.l_ = l;
}
int main (void)
{
return 0;
}
struct Rename
{
public:
union
{
struct
{
float x,y,z,w;
};
struct
{
float vec[4];
};
};
};
struct Compression
{
public:
bool operator==(const Compression& arg) const { return value == arg.value; }
union
{
struct
{
char a,b,c,d,e,f,g;
};
struct
{
long long value;
};
};
};
#include <stdio.h>
void main()
{
union number
{ /*定义一个联合*/
int i;
struct
{ /*在联合中定义一个结构*/
char first;
char second;
}half;
}num;
num.i=0x4241; /*联合成员赋值*/
printf("%c%c\n", num.half.first, num.half.second);
num.half.first='a'; /*联合中结构成员赋值*/
num.half.second='b';
printf("%x\n", num.i);
getchar();
}
union test
{
test() { }
int office;
char teacher[5];
};
union test
{
int office;
char teacher[5];
};
union test a,b; /*说明a,b为test类型*/
union test
{
int office;
char teacher[5];
} a,b;
union
{
int office;
char teacher[5];
} a,b;
#include <iostream>
void main()
{
union{
int test;
char c;
};
test=5;
c='a';
std::cout<<i<<" "<<c;
}
class Test
{
public:
Test():data(0) { }
private:
int data;
};
typedef union _test
{
Test test;
}UI;
class test
{
public:
test(const char* p);
test(int in);
const operator char*() const {return
data.ch;}
operator long() const {return data.l;}
private:
enum type {Int, String };
union
{
const char* ch;
int i;
}datatype;
type stype;
test(test&);
test& operator=(const test&);
};
test::test(const char *p):stype
(String),datatype.ch(p) { }
test::test(int in):stype(Int),datatype.l(i) {
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有