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

c分析面向对象的实现技术

面向对象编程和结构化编程几乎在同一时期出现。但是由于早些时候的机器环境不允许,如内存、cpu等。导致面向对象技术没有得到及时的发展,而同时因为结构化程序对硬件要求不是那么强烈,所以及时的发展起来了。
但是虽然如此,更多的人在谈到面向对象时总觉得是种优越,总觉得"高人一等",自认为c++一定比c优秀。下面通过用c来实现对象,也说明它们之间的关系,以及面向对象的本质实现。
在开发用户管理系统的时候,一般的user类都如此,java实现:
public class User {
String name;
String password;

public User(String n, String pwd) {
this.setName(n);
this.setPassword(pwd);
}
public String getName() {
return this.name;
}
public String getPassword() {
return this.password;
}
public void setName(String n) {
this.name = n;
}
public void setPassword(String pwd) {
this.password = pwd;
}
public String toString(){
return "name:" + this.getName() + ",password:" + this.getPassword();
}
public static void main(String[] args) {
User u = new User("abc","456");
System.out.println(u.toString());
}

}  
 
下面通过c的实现展示如何实现面向对象技术: 
 
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/*
* array.c
*
* Created on: 2009-7-20
* Author: cangyingzhijia
*
* c模拟面向对象实现
*/
struct User;
typedef char * String;
static String _toString(struct User *this);
static String _getPassword(struct User *this);
static String _getName(struct User *this);
static void _setName(struct User *this, String n);
static void _setPassword(struct User *this, String pwd);
static void _construct(struct User *this, String n, String pwd);
static void _destruct(struct User *this);
/**
* 定义方法操作表
*/
static struct operation {
void (*construct)(struct User *this, String n, String pwd);
void (*destruct)(struct User *this);
String (*toString)(struct User *this);
String (*getPassword)(struct User *this);
String (*get


相关文档:

DSP中的C优化

 C6000系列DSP的硬件资源为高性能提高了必要条件,TI公司也配合C6000推出了世界上第一个效率可达70%~80%的汇编语言级C编译器,它产生的代码平均效率是以往DSP编译器的3倍,如何理解并充分利用这些有利资源,使代码达到所期望的性能,是本章的主题。
①     第一阶段:属于纯C阶段,此时不需要 ......

C/C++ 笔记(零碎点)

1)a = a + 5; 与 a += 5;的区别。
    二者在广义上是等价。D.Ritchie 在C语言中引入复合运算符的主要目的是为了提高编译的效率以产生高质量的执行代码。因为这些运算符的功能基本上都能用一二条机器指令来完成。
2)在C++中long 与 int 的区别
NameDescriptionSize*Range*
char
Character or s ......

华为C/C++笔试题3

1. 找错
#define MAX_SRM 256
DSN get_SRM_no()
{
    static int SRM_no;
    int I;
    for(I=0;I<MAX_SRM;I++,SRM_no++)
    {
        SRM_no %= MAX_SRM;
        ......

C标准库源码解剖(12):浮点数环境fenv.h

     为了编写高精度浮点数的运算,编程人员需要控制浮点数环境的各个方面:结果如何舍入,浮点数表达式如何简化与变换,如何处理浮点数异常(如下溢之类的浮点数异常是忽略还是产生错误),等等。C99引入了fenv.h来控制浮点数环境。
    1、fenv.h:
定义了浮点数环境控制函数、异常 ......

linux 下 用c语言创建mysql数据库笔记(二)

linux 下 用c语言创建mysql数据库笔记(二)
                       
-------两个简单的例子,供参考比较
《例一》
#include <stdio.h>
#include <stdlib.h>
#include
&q ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号