易截截图软件、单文件、免安装、纯绿色、仅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优化2

3.4理解编译器的反馈信息
    在编译C代码时,编译器在产生的.asm文件里向程序员反馈了许多信息,理解这些信息,按它的提示修改C代码,对尽快优化代码很有好处。只要用-k令编译器保留.asm文件,就可读到这些信息。
    对于C优化,重点就是循环,对于反馈信息,我们主要考察编译器对流水线 ......

字符串的两种不同风格: C++风格和C风格

这个提法有点怪异,但还是常常出现:
char *p = "abcd";

string str = "abcdefg";
第一个叫做C风格的字符串,原因是有null作为结尾; 第二个为C++风格的, 不是以null结尾.
实质上: C风格的字符串是:
char[] pArr = {'a', 'b', 'c', 'd', '\0'};
这样决定了处理方式的不同 ......

C/C++ 笔试、面试题目大汇总(1)

一位同学整理的常见笔试/面试题目,答案仅供参考,不代表本人观点。
这个东西有些参考价值,和同学讨论一下发现还是有些错误,
1.已知strcpy函数的原型是:
char * strcpy(char * strDest,const char * strSrc);
1.不调用库函数,实现strcpy函数。
2.解释为什么要返回char *。
解说:
1.strcpy的实现代码
char * st ......

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

linux 下 用c语言创建mysql数据库笔记(一)
     
-----仅为个人学习摘要,并不断更新中。。。。
在引用头文件时必须包含‘mysql.h’的头文件(必须是mysql.h的绝对地址,一般在mysql下的include目录下,仔细看看你的在哪里?*),
我是ubuntu9。04,在/usr/include/mysql/mysql ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号