C + +: In the case of memory management, the overall feeling is very cool, and because it is a UNIX self-brought compiler. Very cool. The only point is that an enumeration value in an enumeration type is like a global variable name. The enumeration values are named very long. The syntax is basically not too many pauses, and the syntax involved in this example is much like the C#,java.
#include <iostream>using namespacestd;enumenum_op{Enum_op_add, Enum_op_minus, Enum_op_time, enum_op_divide};intNumbercaculate (intAintb,enum_op op) { intret=0; Switch(OP) { Caseenum_op_add: {ret=a+b; Break; } CaseEnum_op_minus: {ret=a-b; Break; } Caseenum_op_time: {ret=a*b; Break; } Caseenum_op_divide: {ret=a/b; } } returnret;} Template<typename t>t Numbercaculatefull (t a,t b,enum_op op) {t ret=0; Switch(OP) { Caseenum_op_add: {ret=a+b; Break; } CaseEnum_op_minus: {ret=a-b; Break; } Caseenum_op_time: {ret=a*b; Break; } Caseenum_op_divide: {ret=a/C; } } returnret;}intMain () {cout<<"Hello,world"<<Endl; cout<<numbercaculate (1,3, Enum_op_minus) <<Endl; cout<<NumberCaculateFull<float> (1.2,3.3, Enum_op_time) <<Endl;}
Object-c: Because there is Xcode, the second-largest editor of the Earth (vs first), writing code is still cool. Unlike C + +, where the enum ENUM_OP op is defined for the parameters in the enumeration, it is important that generics are not fully supported. This is a gap.
////main.m//Hiworld////Created by Linson on 2018/8/19.//Copyright 2018 Linson. All rights reserved.//#import<Foundation/Foundation.h>enumenum_op{Enum_op_add, Enum_op_minus, Enum_op_time, enum_op_divide};intNumbercaculate (intAintBenumenum_op op);intMainintargcConst Char*argv[]) {@autoreleasepool {NSLog (@"Hello, world!."); intA=2; intb=4; NSLog (@"%i", Numbercaculate (A, B, Enum_op_add)); NSLog (@"%i", Numbercaculate (A, B, Enum_op_minus)); } return 0;}intNumbercaculate (intAintBenumenum_op op) { intret=0; Switch(OP) { Caseenum_op_add: {ret=a+b; Break; } CaseEnum_op_minus: {ret=a-C; Break; } Caseenum_op_time: {ret=a*b; Break; } Caseenum_op_divide: {ret=a/b; } } returnret;}
Basic grammatical comparison of several common languages: digital processing