/* * Copyright (c) 2020 AIIT XUOS Lab * XiUOS is licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: * http://license.coscl.org.cn/MulanPSL2 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. */ #include #include #include using namespace std; extern "C" void KPrintf(const char *fmt, ...); class Animal //parent class { public: virtual void Eat() { KPrintf("eat\n"); } void Sleep() { KPrintf("sleep\n"); } }; class Fish :public Animal //subclass { public: void Eat() { KPrintf("fish eat\n"); } }; void Doeat(Animal& animal) { animal.Eat(); } void MemTest2() { int i; char *ptr = NULL; /* memory pointer */ for (i = 0; ; i++) { /* allocate (1< void MySwap(T& a, T& b) { T temp = a; a = b; b = temp; } extern "C" int cppmain(void) { MemTest2(); class Fish fish; Doeat(fish); int a = 3; int b = 5; void OverLoadTestDouble(int a, int b); OverLoadTestDouble(a, b); MySwap(a,b); KPrintf("with template the output is: %d and %d\n", a,b); return 0; }