//class_main2.cpp#include<stdio.h>#include<string>#include"class_2.h"intmain(){
Circle* n =(Circle*)malloc(sizeof(Circle));// Circle not use gzhs to create object truely
Circle obj;// Eorr: Circle obj();
Circle obj0(1,2,3);
obj.SetRadius(1);
obj.MoveTo(0,0);double aras = obj.Area();{
Circle obj1(2,2,3);double aras1 = obj1.Area();}
Object obj2;int* m =newint(0);// int* m = new int(); int* m = new int;int* p =newint[2];
p[0]=1;
p[1]=2;delete m;
m =NULL;delete[] p;
p =NULL;return0;}
// class_main3.cpp#include<stdio.h>#include<stdlib.h>#include<string.h>classTutorial{public:char name[32];char author[16];public:Tutorial(char* n ,char* a){strcpy(name, n);strcpy(author, a);}voidShowInfo(){printf("Tourial1: %s, %s\n",name ,author);}virtualvoidmybcx(){printf("miang yao bei chong xie!");}virtualvoidcxhs()=0;virtual~Tutorial(){}// must add virtual private:int iprivate;protected:int iprotected;};classViodeTuorial:public Tutorial {public:ViodeTuorial():url("www"),visits(1),Tutorial("C yu yan","wl"){// Eorr: iprotected(100), name("mr")
iprotected =100;}voidPlay(){printf("PLAY");}public:char url[128];int visits;public:voidShowInfo(){
Tutorial::ShowInfo();printf("Tourial2: %s, %s\n", name, author);}voidmybcx(){printf("zhi xing de shi wo!");}voidcxhs(){}};intmain(){
ViodeTuorial cpp_guide;strcpy(cpp_guide.author,"shaofa");strcpy(cpp_guide.name,"C/C++ zhinan");// include 00 -> 13// Eorr: cpp_guide.iprotected = 100;
cpp_guide.ShowInfo();printf("%d,%d\n",sizeof(cpp_guide.name),strlen(cpp_guide.name));// 32, 12
Tutorial* p =newViodeTuorial();
p->mybcx();// virtual , zhi xing child's functiondelete p;// first delete child's ~ ,because of virtual ~Tutorial() {}}