1 /* 2 * Copyright (C) 2015-2017 Alibaba Group Holding Limited 3 */ 4 5 #include "aos/kernel.h" 6 #include <aos_cpp.h> 7 #include <iostream> 8 #include <stdio.h> 9 10 using namespace std; 11 12 extern "C" int application_start(int argc, char *argv[]); 13 14 class A { 15 public: 16 int a; foo()17 void foo() { cout << "A class foo." << endl; } fun()18 virtual void fun() { cout << "A class fun." << endl; } 19 A()20 A() { a = 5; } 21 }; 22 23 class B : public A { 24 public: 25 int b; foo()26 void foo() { cout << "B class foo." << endl; } fun()27 void fun() { cout << "B class fun." << endl; } 28 B()29 B() { b = 10; } 30 }; 31 32 static B static_class_b; 33 static_class_test(void)34static void static_class_test(void) 35 { 36 printf("B member b value is %d.\n", static_class_b.b); 37 printf("B member a value is %d.\n", static_class_b.a); 38 } 39 class_ploy_test(void)40static void class_ploy_test(void) 41 { 42 A *pa = new A; 43 B *pb = new B; 44 A *pc = (A *)pb; 45 46 pa->foo(); 47 pa->fun(); 48 49 pb->foo(); 50 pb->fun(); 51 52 pc->foo(); 53 pc->fun(); 54 55 delete pa; 56 delete pb; 57 } 58 division(int a,int b)59static double division(int a, int b) 60 { 61 if (b == 0) { 62 throw "Division by zero condition!"; 63 } 64 return (a / b); 65 } 66 exception_test(void)67static void exception_test(void) 68 { 69 int x = 50; 70 int y = 0; 71 double z = 0; 72 73 try { 74 z = division(x, y); 75 cout << z << endl; 76 } catch (const char *msg) { 77 cout << "catch exception" << endl; 78 cerr << msg << endl; 79 } 80 } 81