| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1248 人关注过本帖
标题:[原创]结构体
只看楼主 加入收藏
zhangzujin
Rank: 1
等 级:新手上路
帖 子:276
专家分:0
注 册:2005-5-9
收藏
 问题点数:0 回复次数:1 
[原创]结构体

#include "stdafx.h"

#using <mscorlib.dll>

using namespace System;

__value struct contact
{
public:
String *email;
long telephone;

contact(String *email,long telephone)
{
this->email=email;
this->telephone=telephone;
}
};

__value struct student
{
public:
long id;
String *name;
String *dept;
contact con;

student(long id,String *name,String *dept,contact con)
{
this->id=id;
this->name=name;
this->dept=dept;
this->con=con;
}

void ShowId( )
{
Console::Write("id=");
Console::WriteLine(this->id);
}

void ShowEmail( )
{
Console::Write("email=");
Console::WriteLine(this->con.email);
}
};

int _tmain()
{
student a,b;

a.id=130103106;
a.name="zhangzujin";
a.dept="math";
a.con.email="zhangzujin360732@163.com";
a.con.telephone=8663057;
a.ShowId( );

contact acon("yangxj4746@163.com",8663045);
b=student(1301030105,"yangxiji","biology",acon);
b.ShowEmail( );

return 0;
}


结构体和类:
1)结构体是值类型,而泪湿引用类型。
2)结构体的各成员的访问控制方式都缺省为公有的,而类的各成员访问方式则缺省为私有的。
3)结构体能更有效的利用内存。

搜索更多相关主题的帖子: String 结构体 telephone long email 
2006-01-11 22:32
冰镇柠檬汁儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:北京
等 级:版主
威 望:120
帖 子:8078
专家分:6657
注 册:2005-11-7
收藏
得分:0 

本来无一物,何处惹尘埃
It is empty at all here, Why pm 2.5 is so TMD high!
2006-01-13 08:22
快速回复:[原创]结构体
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014185 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved