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
相关文档:
1、 int a=2,b=11,c=a+b++/a++; 则c值为多少?
【考点】编码规范。
表面上考察你对运算符优先级的掌握程度,但实际上优先级这些玩意很难死记硬背得住?大家的疑惑不就是运算符的结合顺序么?那么如何去避免呢?c=a+((b++)/(a++))不就行了么,其实问题背后考察的是你的编码规范,如何写清晰易懂的代码,如何在一个团 ......
这两天学习C++学累了,看了很多的网站论坛,突然感觉迷茫了,c/c++到底能做什么呢?现在JAVA很热,也很好找工作,而且学起来还听说很容易入门。不用学计算机基础类的知识,可C/C++就不同了,只学编程还不行,还得学什么数据结构,算法,计算机原理,操作系统,汇编语言,编程用具等等,需要好多,感觉一 ......
C的变参问题与print函数的实现
我们在C语言编程中会遇到一些参数个数可变的函数,例如printf() 这个函数,它的定义是这样的: int printf( const char* format, ...);
它除了有一个参数format固定以外,后面跟的参数的个数和类型是可变的,例如我们可以有以下不同的调用方法:
printf("%d",i);
&nb ......
static
C++中的static
C++的static有两种用法:面向过程程序设计中的static和面向对象程序设计中的static。前者应用于普通变量和函数,不涉及类;后者主要说明static在类中的作用。
一、面向过程设计中的static
1、静态全局变量
在全局变量前,加上关键字static,该变量就被定义成为一个静态全局变 ......