#include <iostream>
using namespace std;
struct c1 {
int get_i();
void put_i(int j); //默认情况下这些成员是公有的
private:
int i;
};
int c1::get_i()
{
return i;
}
void c1::put_i(int j)
{
i = j;
}
int main()
{
c1 s;
s.put_i(10);
cout << s.get_i() << "\n";
return 0;
}
$ ./structo
10
#include <iostream>
using namespace std;
union u_type {
u_type (short int a);
void showchars();
short int i;
char ch[2];
};
u_type::u_type(short int a)
{
i = a;
}
void u_type::showchars()
{
cout << ch[0] << " ";
cout << ch[1] << "\n";
}
int main()
{
u_type u(22872);
u.showchars();
return 0;
}
$ ./unionto
X Y
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |