易截截图软件、单文件、免安装、纯绿色、仅160KB

C: 面向对象(3)

以下代码演示如何用C来模拟多态。gcc版本:3.4.4
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#ifndef class
        #define class struct
#endif
#ifndef private
        #define private
#endif
#ifndef public
        #define public
#endif
#ifndef protected
        #define protected
#endif
#ifndef bool
        #define bool int
#endif
#ifndef true
        #define true 1
#endif
#ifndef false
        #define false 0
#endif
class Parent{
      //private members
      private class Parent *this;
      private size_t len;
     
      //public members
      public size_t (*length)(class Parent *this);
      public void (*construct)(class Parent *this);
      public void (*print)(class Parent *this);
      public void (*destruct)(class Parent *this);
};
class Son{
      //private members
      private class Son *this;
      //inherit
      private class Parent *inherit;
     
      //public members
      public size_t (*length)(class Son *this);
      public bool (*construct)(class Son *this);
      public void (*print)(class Son *this);
      public void (*destruct)(class Son *this);
};
//forward declaration
void ParentConstruct(class Parent *this);
void ParentPr


相关文档:

C/C++时间函数的使用

一、获取日历时间
time_t是定义在time.h中的一个类型,表示一个日历时间,也就是从1970年1月1日0时0分0秒到此时的秒数,原型是:
 typedef long time_t;        /* time value */
可以看出time_t其实是一个长整型,由于长整型能表示的数值有限,因此它能表示的最迟时间是2038年 ......

C#中C/C++程序员注意问题

1、C/C++程序员请注意,不能在case语句不为空时“向下执行”。
  2、值类型和引用类型之间的区别:C#的基本类型(int,char等)都是值类型,是在栈中创建的。而对象是引用类型,创建于堆中,需要使用关键字new。
  3、在C#中通过实例访问静态方法或成员变量是不合法的,会生成编译器错误。但是我们可以通过声 ......

更高效率的A^B mod C bird

#include <stdio.h>
#define LL unsigned long long int

inline LL mod(LL a,LL b)
{
while (a>=b)
a-=b;
return a;
}
//a*b mod c
inline LL MulAndMod(LL a, LL shl_b,LL c)
{
LL val,pre;
pre = mod(a,c);
val = 0;
......

使用Visual C 加速键和菜单

菜单和加速键密切地联系在一起。这两种资源类型联手协作,让用户能更容易地完成任务。大家都知道菜单是什么——它是分层命令结构的物理表示。加速键提供该结构的快捷方式,以提高用户操作的速度。例如,要创建一个新文件,通常用File | New(文件|新建)命令或CTRL-N加速键,两种方法可以产生相同的结果。
Visua ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号