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的变参问题与print函数的实现
我们在C语言编程中会遇到一些参数个数可变的函数,例如printf() 这个函数,它的定义是这样的: int printf( const char* format, ...);
它除了有一个参数format固定以外,后面跟的参数的个数和类型是可变的,例如我们可以有以下不同的调用方法:
printf("%d",i);
&nb ......
1、C/C++程序员请注意,不能在case语句不为空时“向下执行”。
2、值类型和引用类型之间的区别:C#的基本类型(int,char等)都是值类型,是在栈中创建的。而对象是引用类型,创建于堆中,需要使用关键字new。
3、在C#中通过实例访问静态方法或成员变量是不合法的,会生成编译器错误。但是我们可以通过声 ......
命令行界面的程序,通常都需要输入命令行参数帮助程序执行。main是最典型的此类应用,main的参数之前都被忽略掉了。
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int count;
printf("The command line has %d arguments:\n", ......
本试题仅用于考查C++/C程序员的基本编程技能。内容限于C++/C常用语法,不涉及数据结构、算法以及深奥的语法。考试成绩能反映出考生的编程质量以及对C++/C的理解程度,但不能反映考生的智力和软件开发能力。
笔试时间90分钟。请考生认真答题,切勿轻视。
一、请填写BOOL , float, 指针变量 与“零值”比较的 i ......