给宝宝的作业
来源:互联网 发布:软件体系结构 张友生 编辑:程序博客网 时间:2024/04/27 21:43
schema.h:
# ifndef _SCHEMA_H_
# define _SCHEMA_H_
# include "stdafx.h"
# include "stddef.h"
using namespace std;
// 这里的宏中的s为类变量或者结构体
// y是这种的变量类型,
// x为变量名称!
# define SCHEMAT(x,y,s) sizeof(y) , offsetof(s,x) , sizeof(( (s*)(0) )->x)/sizeof(y)
class schema
{
public:
//char* name;
struct schemakobe
{
schemakobe* schemanext;
int size;
int offset;
int elem;
char* unit;
char* comment;
};
schema( );
~schema( );
void copydata( void* source , void* des , int size , schemakobe* sche );
schemakobe* nextrecord( schemakobe* current );
};
# endif
diceng.cpp:
// diceng.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "schema.h"
# define NUM 10
using namespace std;
class libo : public schema
{
public:
int age;
char gender[7];
char gf[7];
libo( )
{
cout << "李博宝宝正在成功构建!" << endl;
}
~libo( )
{
cout << "李博宝宝正在离开!" << endl;
}
libo& operator = ( const libo& source) ;
};
schema::schemakobe libodangan[] =
{
{NULL , SCHEMAT( age , int , libo ) , "year" , "李博的年龄"},
{NULL , SCHEMAT( gender , char , libo) , "" , "李博的性别" },
{NULL , SCHEMAT( gf , char , libo ) , "" , "李博的女朋友" },
{0}
};
libo& libo::operator =(const libo& source)
{
if( &source == NULL )
{
cout << "没有需要复制的东西!" << endl;
}
else
{
copydata( (void*)this , (void*)&source , sizeof( source ) ,libodangan);
}
return *this;
}
int _tmain(int argc, _TCHAR* argv[])
{
libo libobaobao;
libobaobao.age = 24;
strcpy_s( libobaobao.gender , sizeof("男性") , "男性");
strcpy_s( libobaobao.gf , sizeof("小溪儿") , "小溪儿");
cout << libobaobao.age;
cout << endl;
cout << libobaobao.gender;
cout << endl;
cout << libobaobao.gf;
cout << endl;
libo liboxiaoxidebaobao;
liboxiaoxidebaobao = libobaobao;
cout << liboxiaoxidebaobao.age << endl;
cout << liboxiaoxidebaobao.gender << endl;
return 0;
}
schema.cpp:
# include "stdafx.h"
# include "schema.h"
using namespace std;
schema::schema(){}
schema::~schema(){}
void schema::copydata(void *des, void *source, int size , schemakobe* sche)
{
schemakobe* temp = sche;
if( sche == NULL )
{
cout << "该类中的内容为空!" << endl;
}
else
{
//if( sche->schemanext != NULL )
//{
while( temp != NULL )
{
for( int i = 0 ; i < temp->elem ; i++)
{
if( temp->schemanext == NULL )
{
memcpy( (char*)des + temp->offset + i * temp->size , (char*)source + temp->offset + i * temp->size , temp->size );
}
else
{
//xiaotemp = nextrecord( temp );
copydata( (char*)source + temp->offset , (char*)des + temp->offset , temp->size , temp->schemanext);
}
}
temp = nextrecord( temp );
if( temp == NULL )
{
break;
}
}
//}
}
}
schema::schemakobe* schema::nextrecord(schema::schemakobe *current)
{
if( current == NULL )
{
return NULL;
}
current++;
if( current->size == 0 )
{
return NULL;
}
else
{
return current;
}
}
实现数据的相互转换,同时还要谢大哥O(∩_∩)O~
- 给宝宝的作业
- 给宝宝的营养早餐
- 给宝宝修剪指甲的小窍门
- 给宝宝补钙的健康新钙念
- 奶奶给宝宝做的鞋
- 母乳喂养 给宝宝最大的健康
- 给宝宝的固态硬盘装机教程
- 给宝宝取名须知!
- 给宝宝挑泳衣
- 狗年宝宝起名大全:爸爸妈妈如何给宝宝选取合适的名字
- 希望早点给我们家宝宝,一个温暖的家
- 平淡生活:给女宝宝取名的学问
- 我来说说我给宝宝买保险的事
- 给宝宝剃满月头是不科学的
- 给宝宝起名要遵循的几点建议
- 如何给宝宝取一个高雅有内涵的名字
- 按生辰八字给宝宝取名的方法步骤
- 给学生留的作业
- 改变互联网的PHP程序
- 我的Trac学习经验
- 我是菜鸟,我要奋斗!
- Google C++编程风格指南(四):智能指针和其他C++特性
- FreeBSD源码学习(2):echo命令源码分析
- 给宝宝的作业
- Google C++编程风格指南(五):命名约定
- 无所不在的9
- Google C++编程风格指南(六):代码注释
- JDK的几种分析工具
- J2ME对短消息/语音电话功能的支持情况
- Google C++编程风格指南(七):格式
- Google C++编程风格指南(八):规则之例外
- C++各阶段学习书目