C: 面向对象(2)
演示如何用C实现继承,重载之类的玩艺儿。VC++6.0编译通过。
#include <stdio.h>
#include <stdlib.h>
#include <string.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 char *name;
//public members
public void (*construct)(class Parent *this);
public bool (*setName)(class Parent *this, const char *name);
public char* (*getName)(class Parent *this);
public void (*destruct)(class Parent *this);
};
class Son{
//private members
private class Son *this;
//inherit properties from Parent, we use a pointer here to simulate inheritance
private class Parent *inherit;
//add new members
private char* addr;
//public members
public bool (*construct)(class Son *this);
public bool (*setName)(class Son *this, const char *name);
public char* (*getName)(class Son *this);
public bool (*setAddr)(class Son *this, const char *addr);
public char* (*getAddr)(class Son *this);
public void (*destruct)(class Son *this);
};
//foward declaration
//-----Members for Parent begin
void ParentConstruct(class Parent *this);
bool setName(class Parent *this, const char *name);
char *getName(class Parent *this);
void ParentDestruct(class Parent *this);
//-----Mmmbers for Parent end
//----Members for Son begin
bool SonConstruct(clas
相关文档:
这两天学习C++学累了,看了很多的网站论坛,突然感觉迷茫了,c/c++到底能做什么呢?现在JAVA很热,也很好找工作,而且学起来还听说很容易入门。不用学计算机基础类的知识,可C/C++就不同了,只学编程还不行,还得学什么数据结构,算法,计算机原理,操作系统,汇编语言,编程用具等等,需要好多,感觉一 ......
/*
coder: ACboy
date: 2010-3-14
result: 1A
description: UVa 327 Evaluating Simple C Expressions
*/
#include <iostream>
#include <algorithm>
using namespace std;
struct Node {
char name;
int value;
int lastValue;
int pos;
};
int cmp(const Node & a, const Node &a ......
一、获取日历时间
time_t是定义在time.h中的一个类型,表示一个日历时间,也就是从1970年1月1日0时0分0秒到此时的秒数,原型是:
typedef long time_t; /* time value */
可以看出time_t其实是一个长整型,由于长整型能表示的数值有限,因此它能表示的最迟时间是2038年 ......
C的变参问题与print函数的实现
我们在C语言编程中会遇到一些参数个数可变的函数,例如printf() 这个函数,它的定义是这样的: int printf( const char* format, ...);
它除了有一个参数format固定以外,后面跟的参数的个数和类型是可变的,例如我们可以有以下不同的调用方法:
printf("%d",i);
&nb ......
今天突然想到B/S结构里,webform是无法取得客户端的MAC地址和硬件信息的,就突发奇想,用C/S结构,但是因为C/S结构的很多的东西不能动态,就考虑到了C/B结构
最后决定用webservice+ALC+C/B结构 ,搭建我的OA系统
努力ing ......