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
相关文档:
这篇文章是使用SQLite C/C++接口的一个概要介绍和入门指南。
由于早期的SQLite只支持5个C/C++接口,因而非常容易学习和使用,但是随着SQLite功能的增强,新的C/C++接口不断的增加进来,到现在有超过150个不同的API接口。这往往使初学者望而却步。幸运的是,大多数SQLite中的C/C++接口是专用的,因而很少被使用到。尽管有这 ......
1)a = a + 5; 与 a += 5;的区别。
二者在广义上是等价。D.Ritchie 在C语言中引入复合运算符的主要目的是为了提高编译的效率以产生高质量的执行代码。因为这些运算符的功能基本上都能用一二条机器指令来完成。
2)在C++中long 与 int 的区别
NameDescriptionSize*Range*
char
Character or s ......
#include<stdio.h>
#include<stdarg.h>
#include<string.h>
void demo(char *msg,...)
{
va_list argp;
int arg_number=0;
char *para = msg;
va_start(argp,msg);
while(1){
if ( strcmp( para, "\0") != 0 ) {
arg_number++;
printf("parameter %d is: %s\n",arg_number,p ......
格式:文件指针名=fopen(文件名,使用文件方式)
参数:
文件名 意义
"C:\\TC\\qwe.txt" 文件C:\TC\qwe.txt
"qwe.txt" 和程序在同一目录下的qwe.txt
文件使用方式 意 义
“rt” 只读打开一个文本文件,只允许读数据
“wt” 只写打开或建立一个文本文件,只允许写数据 ......
linux 下 用c语言创建mysql数据库笔记(一)
-----仅为个人学习摘要,并不断更新中。。。。
在引用头文件时必须包含‘mysql.h’的头文件(必须是mysql.h的绝对地址,一般在mysql下的include目录下,仔细看看你的在哪里?*),
我是ubuntu9。04,在/usr/include/mysql/mysql ......