给宝宝的作业

来源:互联网 发布:软件体系结构 张友生 编辑:程序博客网 时间:2024/06/10 04:30

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~

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 做外汇被坑怎么办?亏损二十多万 iphone储存空间已满怎么办 icloud储存空间将满怎么办 手机店没人进店怎么办 淘宝退货运单填错了怎么办 淘宝快递单号填错了怎么办 拼多多48小时不发货怎么办 想开化妆品店没有经验怎么办 淘宝卖家收钱不发货怎么办 nike拖鞋买小了怎么办 京东换货没货了怎么办 淘宝申请退货退款卖家不处理怎么办 家具连接扣坏了怎么办 锅炉炉水碱度低怎么办 快递里面的东西少了怎么办 很多闲置在家里的东西怎么办 闲鱼买的东西与原物不对怎么办 退款后又发货了怎么办 淘宝卖家不发货也不退款怎么办 已经申请退款卖家仍发货怎么办 淘宝卖家已发货买家申请退款怎么办 爱上街App不发货怎么办 阿里卖家虚假发货怎么办 联系不到淘宝卖家怎么办 没货买家不退款怎么办 买到假货没有发票怎么办 淘宝买的手机发票怎么办 淘宝上的发票丢了怎么办 淘宝买的东西电子发票怎么办 发票联给错顾客怎么办 客人让多给发票怎么办 13岁早晨上学叫不醒怎么办 官换机过保坏了怎么办 官换机在保坏了怎么办 留学生美国东西寄回国怎么办便宜 淘宝东西没到收货了怎么办 在淘宝上买东西被骗怎么办 网上把钱骗走了怎么办 在淘宝上卖号被骗了怎么办 如果淘宝商家保证金不够退款怎么办 天猫账号忘记了怎么办