{
  "58954436": [],
  "58954437": [],
  "58954438": [
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "#include<iostream>\nusing namespace std;\n\nint main(){\t\n\tcout << \"hello world\" << endl;\n\treturn EXIT_SUCCESS;\n}"
    }
  ],
  "58954439": [
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//全局变量\nint a = 10;\nvoid test(){\n\t//局部变量\n\tint a = 20;\n\t//全局a被隐藏\n\tcout << \"a:\" << a << endl;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//全局变量\nint a = 10;\n//1. 局部变量和全局变量同名\nvoid test(){\n\tint a = 20;\n\t//打印局部变量a\n\tcout << \"局部变量a:\" << a << endl;\n\t//打印全局变量a\n\tcout << \"全局变量a:\" << ::a << endl;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "namespace A{\n\tint a = 10;\n}\nnamespace B{\n\tint a = 20;\n}\nvoid test(){\n\tcout << \"A::a : \" << A::a << endl;\n\tcout << \"B::a : \" << B::a << endl;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "void test(){\n\tnamespace A{\n\t\tint a = 10;\n\t}\n\tnamespace B{\n\t\tint a = 20;\n\t}\n\tcout << \"A::a : \" << A::a << endl;\n\tcout << \"B::a : \" << B::a << endl;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "namespace A{\n\tint a = 10;\n\tnamespace B{\n\t\tint a = 20;\n\t}\n}\nvoid test(){\n\tcout << \"A::a : \" << A::a << endl;\n\tcout << \"A::B::a : \" << A::B::a << endl;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "namespace A{\n\tint a = 10;\n}\n\nnamespace A{\n\tvoid func(){\n\t\tcout << \"hello namespace!\" << endl;\n\t}\n}\n\nvoid test(){\n\tcout << \"A::a : \" << A::a << endl;\n\tA::func();\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "namespace MySpace{\n\tvoid func1();\n\tvoid func2(int param);\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "void MySpace::func1(){\n\tcout << \"MySpace::func1\" << endl;\n}\nvoid MySpace::func2(int param){\n\tcout << \"MySpace::func2 : \" << param << endl;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "namespace{\n\tint a = 10;\n\tvoid func(){ cout << \"hello namespace\" << endl; }\n}\nvoid test(){\n\tcout << \"a : \" << a << endl;\n\tfunc();\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "namespace veryLongName{\n\t\n\tint a = 10;\n\tvoid func(){ cout << \"hello namespace\" << endl; }\n}\n\nvoid test(){\n\tnamespace shortName = veryLongName;\n\tcout << \"veryLongName::a : \" << shortName::a << endl;\n\tveryLongName::func();\n\tshortName::func();\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "namespace A{\n\tint paramA = 20;\n\tint paramB = 30;\n\tvoid funcA(){ cout << \"hello funcA\" << endl; }\n\tvoid funcB(){ cout << \"hello funcA\" << endl; }\n}\n\nvoid test(){\n\t//1. 通过命名空间域运算符\n\tcout << A::paramA << endl;\n\tA::funcA();\n\t//2. using声明\n\tusing A::paramA;\n\tusing A::funcA;\n\tcout << paramA << endl;\n\t//cout << paramB << endl; //不可直接访问\n\tfuncA();\n\t//3. 同名冲突\n\t//int paramA = 20; //相同作用域注意同名冲突\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "namespace A{\n\tvoid func(){}\n\tvoid func(int x){}\n\tint  func(int x,int y){}\n}\nvoid test(){\n\tusing A::func;\n\tfunc();\n\tfunc(10);\n\tfunc(10, 20);\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "namespace A{\n\tint paramA = 20;\n\tint paramB = 30;\n\tvoid funcA(){ cout << \"hello funcA\" << endl; }\n\tvoid funcB(){ cout << \"hello funcB\" << endl; }\n}\n\nvoid test01(){\n\tusing namespace A;\n\tcout << paramA << endl;\n\tcout << paramB << endl;\n\tfuncA();\n\tfuncB();\n\n\t//不会产生二义性\n\tint paramA = 30;\n\tcout << paramA << endl;\n}\n\nnamespace B{\n\tint paramA = 20;\n\tint paramB = 30;\n\tvoid funcA(){ cout << \"hello funcA\" << endl; }\n\tvoid funcB(){ cout << \"hello funcB\" << endl; }\n}\n\nvoid test02(){\n\tusing namespace A;\n\tusing namespace B;\n\t//二义性产生，不知道调用A还是B的paramA\n\t//cout << paramA << endl;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "int a = 10; //赋值，当做定义\nint a; //没有赋值，当做声明\n\nint main(){\n\tprintf(\"a:%d\\n\",a);\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//i没有写类型，可以是任意类型\nint fun1(i){\n\tprintf(\"%d\\n\", i);\n\treturn 0;\n}\n//i没有写类型，可以是任意类型\nint fun2(i){\n\tprintf(\"%s\\n\", i);\n\treturn 0;\n}\n//没有写参数，代表可以传任何类型的实参\nint fun3(){ \n\tprintf(\"fun33333333333333333\\n\");\n\treturn 0;\n}\n\n//C语言，如果函数没有参数，建议写void，代表没有参数\nint fun4(void){\n\tprintf(\"fun4444444444444\\n\");\n\treturn 0;\n}\n\ng(){\n\treturn 10;\n}\n\nint main(){\n\n\tfun1(10);\n\tfun2(\"abc\");\n\tfun3(1, 2, \"abc\");\n\tprintf(\"g = %d\\n\", g());\n\n\treturn 0;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "typedef enum COLOR{ GREEN, RED, YELLOW } color;\nint main(){\n\tcolor mycolor = GREEN;\n\tmycolor = 10;\n\tprintf(\"mycolor:%d\\n\", mycolor);\n\tchar* p = malloc(10);\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//1. 结构体中即可以定义成员变量，也可以定义成员函数\nstruct Student{\n\tstring mName;\n\tint mAge;\n\tvoid setName(string name){ mName = name; }\n\tvoid setAge(int age){ mAge = age; }\n\tvoid showStudent(){\n\t\tcout << \"Name:\" << mName << \" Age:\" << mAge << endl;\n\t}\n};\n\n//2. c++中定义结构体变量不需要加struct关键字\nvoid test01(){\n\tStudent student;\n\tstudent.setName(\"John\");\n\tstudent.setAge(20);\n\tstudent.showStudent();\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "void test()\n{\tcout << sizeof(false) << endl; //为1，//bool类型占一个字节大小\n\tbool flag = true; // c语言中没有这种类型\n\tflag = 100; //给bool类型赋值时，非0值会自动转换为true(1),0值会自动转换false(0)\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "\tint a = 10;\n\tint b = 20;\n\tprintf(\"ret:%d\\n\", a > b ? a : b);\n\t//思考一个问题，(a > b ? a : b) 三目运算表达式返回的是什么？\n\t\n\t//(a > b ? a : b) = 100;\n\t//返回的是右值"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "\tint a = 10;\n\tint b = 20;\n\tprintf(\"ret:%d\\n\", a > b ? a : b);\n\t//思考一个问题，(a > b ? a : b) 三目运算表达式返回的是什么？\n\n\tcout << \"b:\" << b << endl;\n\t//返回的是左值，变量的引用\n\t(a > b ? a : b) = 100;//返回的是左值，变量的引用\n\tcout << \"b:\" << b << endl;"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "      const int constA = 10;\n      int main(){\n           int* p = (int*)&constA;\n           *p = 200;\n     }"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "    const int constA = 10;\n\n    int* p = (int*)&constA;\n\n    *p = 300;\n\n    printf(\"constA:%d\\n\",constA);\n\n    printf(\"*p:%d\\n\", *p);"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "\tconst int constA = 10;\n\tint* p = (int*)&constA;\n\t*p = 300;\n\tcout << \"constA:\" << constA << endl;\n\tcout << \"*p:\" << *p << endl;"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "\tint b = 10;\n\tconst int constA = b;\n\tint* p = (int*)&constA;\n\t*p = 300;\n\tcout << \"constA:\" << constA << endl;\n\tcout << \"*p:\" << *p << endl;"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "    const Person person; //未初始化age\n\t//person.age = 50; //不可修改\n\tPerson* pPerson = (Person*)&person;\n\t//指针间接修改\n\tpPerson->age = 100;\n\tcout << \"pPerson->age:\" << pPerson->age << endl;\n\tpPerson->age = 200;\n\tcout << \"pPerson->age:\" << pPerson->age << endl;"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "#define PARAM 128\n\nconst short param = 128;\n\nvoid func(short a){\n    cout << \"short!\" << endl;\n}\nvoid func(int a){\n    cout << \"int\" << endl;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "void func1(){\n    const int a = 10;\n    #define A 20\n    //#undef A  //卸载宏常量A\n}\n\nvoid func2(){\n    //cout << \"a:\" << a << endl; //不可访问，超出了const int a作用域\n    cout << \"A:\" << A << endl; //#define作用域从定义到文件结束或者到#undef，可访问\n}\n\nint main(){\n    func2();\n    return EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "namespace MySpace{\n    #define num 1024\n}\n\nvoid test(){\n    //cout << MySpace::NUM << endl; //错误\n    //int num = 100; //命名冲突\n    cout << num << endl;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//1. 认识引用\nvoid test01(){\n\n\tint a = 10;\n\t//给变量a取一个别名b\n\tint& b = a;\n\tcout << \"a:\" << a << endl;\n\tcout << \"b:\" << b << endl;\n\tcout << \"------------\" << endl;\n\t//操作b就相当于操作a本身\n\tb = 100;\n\tcout << \"a:\" << a << endl;\n\tcout << \"b:\" << b << endl;\n\tcout << \"------------\" << endl;\n\t//一个变量可以有n个别名\n\tint& c = a;\n\tc = 200;\n\tcout << \"a:\" << a << endl;\n\tcout << \"b:\" << b << endl;\n\tcout << \"c:\" << c << endl;\n\tcout << \"------------\" << endl;\n\t//a,b,c的地址都是相同的\n\tcout << \"a:\" << &a << endl;\n\tcout << \"b:\" << &b << endl;\n\tcout << \"c:\" << &c << endl;\n}\n//2. 使用引用注意事项\nvoid test02(){\n\t//1) 引用必须初始化\n\t//int& ref; //报错:必须初始化引用\n\t//2) 引用一旦初始化，不能改变引用\n\tint a = 10;\n\tint b = 20;\n\tint& ref = a;\n\tref = b; //不能改变引用\n\t//3) 不能对数组建立引用\n\tint arr[10];\n\t//int& ref3[10] = arr;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "\t//1. 建立数组引用方法一\n\ttypedef int ArrRef[10];\n\tint arr[10];\n\tArrRef& aRef = arr;\n\tfor (int i = 0; i < 10;i ++){\n\t\taRef[i] = i+1;\n\t}\n\tfor (int i = 0; i < 10;i++){\n\t\tcout << arr[i] << \" \";\n\t}\n\tcout << endl;\n\t//2. 建立数组引用方法二\n\tint(&f)[10] = arr;\n\tfor (int i = 0; i < 10; i++){\n\t\tf[i] = i+10;\n\t}\n\tfor (int i = 0; i < 10; i++){\n\t\tcout << arr[i] << \" \";\n\t}\n\tcout << endl;"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//值传递\nvoid ValueSwap(int m,int n){\n\tint temp = m;\n\tm = n;\n\tn = temp;\n}\n//地址传递\nvoid PointerSwap(int* m,int* n){\n\tint temp = *m;\n\t*m = *n;\n\t*n = temp;\n}\n//引用传递\nvoid ReferenceSwap(int& m,int& n){\n\tint temp = m;\n\tm = n;\n\tn = temp;\n}\nvoid test(){\n\tint a = 10;\n\tint b = 20;\n\t//值传递\n\tValueSwap(a, b);\n\tcout << \"a:\" << a << \" b:\" << b << endl;\n\t//地址传递\n\tPointerSwap(&a, &b);\n\tcout << \"a:\" << a << \" b:\" << b << endl;\n\t//引用传递\n\tReferenceSwap(a, b);\n\tcout << \"a:\" << a << \" b:\" << b << endl;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//返回局部变量引用\nint& TestFun01(){\n\tint a = 10; //局部变量\n\treturn a;\n}\n//返回静态变量引用\nint& TestFunc02(){\t\n\tstatic int a = 20;\n\tcout << \"static int a : \" << a << endl;\n\treturn a;\n}\nint main(){\n\t//不能返回局部变量的引用\n\tint& ret01 = TestFun01();\n\t//如果函数做左值，那么必须返回引用\n\tTestFunc02();\n\tTestFunc02() = 100;\n\tTestFunc02();\n\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//发现是引用，转换为 int* const ref = &a;\nvoid testFunc(int& ref){\n\tref = 100; // ref是引用，转换为*ref = 100\n}\nint main(){\n\tint a = 10;\n\tint& aRef = a; //自动转换为 int* const aRef = &a;这也能说明引用为什么必须初始化\n\taRef = 20; //内部发现aRef是引用，自动帮我们转换为: *aRef = 20;\n\tcout << \"a:\" << a << endl;\n\tcout << \"aRef:\" << aRef << endl;\n\ttestFunc(a);\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "struct Teacher{\n\tint mAge;\n};\n//指针间接修改teacher的年龄\nvoid AllocateAndInitByPointer(Teacher** teacher){\n\t*teacher = (Teacher*)malloc(sizeof(Teacher));\n\t(*teacher)->mAge = 200;  \n}\n//引用修改teacher年龄\nvoid AllocateAndInitByReference(Teacher*& teacher){\n\tteacher->mAge = 300;\n}\nvoid test(){\n\t//创建Teacher\n\tTeacher* teacher = NULL;\n\t//指针间接赋值\n\tAllocateAndInitByPointer(&teacher);\n\tcout << \"AllocateAndInitByPointer:\" << teacher->mAge << endl;\n\t//引用赋值,将teacher本身传到ChangeAgeByReference函数中\n\tAllocateAndInitByReference(teacher);\n\tcout << \"AllocateAndInitByReference:\" << teacher->mAge << endl;\n\tfree(teacher);\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "void test01(){\n\tint a = 100;\n\tconst int& aRef = a; //此时aRef就是a\n\t//aRef = 200; 不能通过aRef的值\n\ta = 100; //OK\n\tcout << \"a:\" << a << endl;\n\tcout << \"aRef:\" << aRef << endl;\n}\nvoid test02(){\n\t//不能把一个字面量赋给引用\n\t//int& ref = 100;\n\t//但是可以把一个字面量赋给常引用\n\tconst int& ref = 100; //int temp = 200; const int& ret = temp;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//const int& param防止函数中意外修改数据\nvoid ShowVal(const int& param){\n\tcout << \"param:\" << param << endl;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "#define ADD(x,y) x+y\ninline int Add(int x,int y){\n\treturn x + y;\n}\nvoid test(){\n\tint ret1 = ADD(10, 20) * 10; //希望的结果是300\n\tint ret2 = Add(10, 20) * 10; //希望结果也是300\n\tcout << \"ret1:\" << ret1 << endl; //210\n\tcout << \"ret2:\" << ret2 << endl; //300\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "#define COMPARE(x,y) ((x) < (y) ? (x) : (y))\nint Compare(int x,int y){\n\treturn x < y ? x : y;\n}\nvoid test02(){\n\tint a = 1;\n\tint b = 3;\n\t//cout << \"COMPARE(++a, b):\" << COMPARE(++a, b) << endl; // 3\n\tcout << \"Compare(int x,int y):\" << Compare(++a, b) << endl; //2\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Person{\npublic:\n\tPerson(){ cout << \"构造函数!\" << endl; }\n\tvoid PrintPerson(){ cout << \"输出Person!\" << endl; }\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "void TestFunc01(int a = 10, int b = 20){\n\tcout << \"a + b  = \" << a + b << endl;\n}\n//注意点:\n//1. 形参b设置默认参数值，那么后面位置的形参c也需要设置默认参数\nvoid TestFunc02(int a,int b = 10,int c = 10){}\n//2. 如果函数声明和函数定义分开，函数声明设置了默认参数，函数定义不能再设置默认参数\nvoid TestFunc03(int a = 0,int b = 0);\nvoid TestFunc03(int a, int b){}\n\nint main(){\n\t//1.如果没有传参数，那么使用默认参数\n\tTestFunc01();\n\t//2. 如果传一个参数，那么第二个参数使用默认参数\n\tTestFunc01(100);\n\t//3. 如果传入两个参数，那么两个参数都使用我们传入的参数\n\tTestFunc01(100, 200);\n\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "void TestFunc01(int a,int b,int){\n\t//函数内部无法使用占位参数\n\tcout << \"a + b = \" << a + b << endl;\n}\n//占位参数也可以设置默认值\nvoid TestFunc02(int a, int b, int = 20){\n\t//函数内部依旧无法使用占位参数\n\tcout << \"a + b = \" << a + b << endl;\n}\nint main(){\n\n\t//错误调用，占位参数也是参数，必须传参数\n\t//TestFunc01(10,20); \n\t//正确调用\n\tTestFunc01(10,20,30);\n\t//正确调用\n\tTestFunc02(10,20);\n\t//正确调用\n\tTestFunc02(10, 20, 30);\n\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//1. 函数重载条件\nnamespace A{\n\tvoid MyFunc(){ cout << \"无参数!\" << endl; }\n\tvoid MyFunc(int a){ cout << \"a: \" << a << endl; }\n\tvoid MyFunc(string b){ cout << \"b: \" << b << endl; }\n\tvoid MyFunc(int a, string b){ cout << \"a: \" << a << \" b:\" << b << endl;}\n    void MyFunc(string b, int a){cout << \"a: \" << a << \" b:\" << b << endl;}\n}\n//2.返回值不作为函数重载依据\nnamespace B{\n\tvoid MyFunc(string b, int a){}\n\t//int MyFunc(string b, int a){} //无法重载仅按返回值区分的函数\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "void MyFunc(string b){\n\tcout << \"b: \" << b << endl;\n}\n//函数重载碰上默认参数\nvoid MyFunc(string b, int a = 10){\n\tcout << \"a: \" << a << \" b:\" << b << endl;\n}\nint main(){\n\tMyFunc(\"hello\"); //这时，两个函数都能匹配调用，产生二义性\n\treturn 0;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "void func(){}\nvoid func(int x){}\nvoid func(int x,char y){}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "#ifndef MYMODULE_H\n#define MYMODULE_H\n\n#include<stdio.h>\n\n#if __cplusplus\nextern \"C\"{\n#endif\n\n\tvoid func1();\n\tint func2(int a,int b);\n\n#if __cplusplus\n}\n#endif\n\n#endif"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "#include\"MyModule.h\"\n\nvoid func1(){\n\tprintf(\"hello world!\");\n}\nint func2(int a, int b){\n\treturn a + b;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "#define _CRT_SECURE_NO_WARNINGS\n#include<iostream>\nusing namespace std;\n\n#if 0\n\n\t#ifdef __cplusplus\n\textern \"C\" {\n\t\t#if 0\n\t\t\tvoid func1();\n\t\t\tint func2(int a, int b);\n\t\t#else\n\t\t\t#include\"MyModule.h\"\n\t\t#endif\n\t}\n\n\t#endif\n\n#else\n\n\textern \"C\" void func1();\n\textern \"C\" int func2(int a, int b);\n\n#endif\n\nint main(){\n\tfunc1();\n\tcout << func2(10, 20) << endl;\n\treturn EXIT_SUCCESS;\n}"
    }
  ],
  "58954440": [],
  "58954448": [
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "typedef struct _Person{\n\tchar name[64];\n\tint age;\n}Person;\ntypedef struct _Aninal{\n\tchar name[64];\n\tint age;\n\tint type; //动物种类\n}Ainmal;\n\nvoid PersonEat(Person* person){\n\tprintf(\"%s在吃人吃的饭!\\n\",person->name);\n}\nvoid AnimalEat(Ainmal* animal){\n\tprintf(\"%s在吃动物吃的饭!\\n\", animal->name);\n}\n\nint main(){\n\n\tPerson person;\n\tstrcpy(person.name, \"小明\");\n\tperson.age = 30;\n\tAnimalEat(&person);\n\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//封装两层含义\n//1. 属性和行为合成一个整体\n//2. 访问控制，现实事物本身有些属性和行为是不对外开放\nclass Person{\n//人具有的行为(函数)\npublic:\n\tvoid Dese(){ cout << \"我有钱，年轻，个子又高，就爱嘚瑟!\" << endl;}\n//人的属性(变量)\npublic:\n\tint mTall; //多高，可以让外人知道\nprotected:\n\tint mMoney; // 有多少钱,只能儿子孙子知道\nprivate:\n\tint mAge; //年龄，不想让外人知道\n};\n\nint main(){\n\n\tPerson p;\n\tp.mTall = 220;\n\t//p.mMoney 保护成员外部无法访问\n\t//p.mAge 私有成员外部无法访问\n\tp.Dese();\n\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class A{\n\tint mAge;\n};\nstruct B{\n\tint mAge;\n};\n\nvoid test(){\n\tA a;\n\tB b;\n\t//a.mAge; //无法访问私有成员\n\tb.mAge; //可正常外部访问\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class AccessLevels{\npublic:\n\t//对只读属性进行只读访问\n\tint getReadOnly(){ return readOnly; }\n\t//对读写属性进行读写访问\n\tvoid setReadWrite(int val){ readWrite = val; }\n\tint getReadWrite(){ return readWrite; }\n\t//对只写属性进行只写访问\n\tvoid setWriteOnly(int val){ writeOnly = val; }\nprivate:\n\tint readOnly; //对外只读访问\n\tint noAccess; //外部不可访问\n\tint readWrite; //读写访问\n\tint writeOnly; //只写访问\n};"
    }
  ],
  "58954449": [
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//立方体类\nclass Cub{\npublic:\n\tvoid setL(int l){ mL = l; }\n\tvoid setW(int w){ mW = w; }\n\tvoid setH(int h){ mH = h; }\n\tint getL(){ return mL; }\n\tint getW(){ return mW; }\n\tint getH(){ return mH; }\n\t//立方体面积\n\tint caculateS(){ return (mL*mW + mL*mH + mW*mH) * 2; }\n\t//立方体体积\n\tint caculateV(){ return mL * mW * mH; }\n\t//成员方法\n\tbool CubCompare(Cub& c){\n\t\tif (getL() == c.getL() && getW() == c.getW() && getH() == c.getH()){\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\nprivate:\n\tint mL; //长\n\tint mW; //宽\n\tint mH; //高\n};\n\n//比较两个立方体是否相等\nbool CubCompare(Cub& c1, Cub& c2){\n\tif (c1.getL() == c2.getL() && c1.getW() == c2.getW() && c1.getH() == c2.getH()){\n\t\treturn true;\n\t}\n\treturn false;\n}\n\nvoid test(){\n\tCub c1, c2;\n\tc1.setL(10);\n\tc1.setW(20);\n\tc1.setH(30);\n\n\tc2.setL(20);\n\tc2.setW(20);\n\tc2.setH(30);\n\n\tcout << \"c1面积:\" << c1.caculateS() << \" 体积:\" << c1.caculateV() << endl;\n\tcout << \"c2面积:\" << c2.caculateS() << \" 体积:\" << c2.caculateV() << endl;\n\n\t//比较两个立方体是否相等\n\tif (CubCompare(c1, c2)){\n\t\tcout << \"c1和c2相等!\" << endl;\n\t}\n\telse{\n\t\tcout << \"c1和c2不相等!\" << endl;\n\t}\n\n\tif (c1.CubCompare(c2)){\n\t\tcout << \"c1和c2相等!\" << endl;\n\t}\n\telse{\n\t\tcout << \"c1和c2不相等!\" << endl;\n\t}\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//点类\nclass Point{\npublic:\n\tvoid setX(int x){ mX = x; }\n\tvoid setY(int y){ mY = y; }\n\tint getX(){ return mX; }\n\tint getY(){ return mY; }\nprivate:\n\tint mX;\n\tint mY;\n};\n\n//圆类\nclass Circle{\npublic:\n\tvoid setP(int x,int y){\n\t\tmP.setX(x);\n\t\tmP.setY(y);\n\t}\n\tvoid setR(int r){ mR = r; }\n\tPoint& getP(){ return mP; }\n\tint getR(){ return mR; }\n\t//判断点和圆的关系\n\tvoid IsPointInCircle(Point& point){\n\t\tint distance = (point.getX() - mP.getX()) * (point.getX() - mP.getX()) + (point.getY() - mP.getY()) * (point.getY() - mP.getY());\n\t\tint radius = mR * mR;\n\t\tif (distance < radius){\n\t\t\tcout << \"Point(\" << point.getX() << \",\" << point.getY() << \")在圆内!\" << endl;\n\t\t}\n\t\telse if (distance > radius){\n\t\t\tcout << \"Point(\" << point.getX() << \",\" << point.getY() << \")在圆外!\" << endl;\n\t\t}\n\t\telse{\n\t\t\tcout << \"Point(\" << point.getX() << \",\" << point.getY() << \")在圆上!\" << endl;\n\t\t}\n\t}\nprivate:\n\tPoint mP; //圆心\n\tint mR; //半径\n};\n\nvoid test(){\n\t//实例化圆对象\n\tCircle circle;\n\tcircle.setP(20, 20);\n\tcircle.setR(5);\n\t//实例化点对象\n\tPoint point;\n\tpoint.setX(25);\n\tpoint.setY(20);\n\n\tcircle.IsPointInCircle(point);\n}"
    }
  ],
  "58954451": [
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Person{\npublic:\n\tPerson(){\n\t\tcout << \"构造函数调用!\" << endl;\n\t\tpName = (char*)malloc(sizeof(\"John\"));\n\t\tstrcpy(pName, \"John\");\n\t\tmTall = 150;\n\t\tmMoney = 100;\n\t}\n\t~Person(){\n\t\tcout << \"析构函数调用!\" << endl;\n\t\tif (pName != NULL){\n\t\t\tfree(pName);\n\t\t\tpName = NULL;\n\t\t}\n\t}\npublic:\n\tchar* pName;\n\tint mTall;\n\tint mMoney;\n};\n\nvoid test(){\n\tPerson person;\n\tcout << person.pName << person.mTall << person.mMoney << endl;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Person{\npublic:\n\tPerson(){\n\t\tcout << \"no param constructor!\" << endl;\n\t\tmAge = 0;\n\t}\n\t//有参构造函数\n\tPerson(int age){\n\t\tcout << \"1 param constructor!\" << endl;\n\t\tmAge = age;\n\t}\n\t//拷贝构造函数(复制构造函数) 使用另一个对象初始化本对象\n\tPerson(const Person& person){\n\t\tcout << \"copy constructor!\" << endl;\n\t\tmAge = person.mAge;\n\t}\n\t//打印年龄\n\tvoid PrintPerson(){\n\t\tcout << \"Age:\" << mAge << endl;\n\t}\nprivate:\n\tint mAge;\n};\n//1. 无参构造调用方式\nvoid test01(){\n\t\n\t//调用无参构造函数\n\tPerson person1; \n\tperson1.PrintPerson();\n\n\t//无参构造函数错误调用方式\n\t//Person person2();\n\t//person2.PrintPerson();\n}\n//2. 调用有参构造函数\nvoid test02(){\n\t\n\t//第一种 括号法，最常用\n\tPerson person01(100);\n\tperson01.PrintPerson();\n\n\t//调用拷贝构造函数\n\tPerson person02(person01);\n\tperson02.PrintPerson();\n\n\t//第二种 匿名对象(显示调用构造函数)\n\tPerson(200); //匿名对象，没有名字的对象\n\n\tPerson person03 = Person(300);\n\tperson03.PrintPerson();\n\n\t//注意: 使用匿名对象初始化判断调用哪一个构造函数，要看匿名对象的参数类型\n\tPerson person06(Person(400)); //等价于 Person person06 = Person(400);\n\tperson06.PrintPerson();\n\n\t//第三种 =号法 隐式转换\n\tPerson person04 = 100; //Person person04 =  Person(100)\n\tperson04.PrintPerson();\n\n\t//调用拷贝构造\n\tPerson person05 = person04; //Person person05 =  Person(person04)\n\tperson05.PrintPerson();\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Person{\npublic:\n\tPerson(){\n\t\tcout << \"no param contructor!\" << endl;\n\t\tmAge = 10;\n\t}\n\tPerson(int age){\n\t\tcout << \"param constructor!\" << endl;\n\t\tmAge = age;\n\t}\n\tPerson(const Person& person){\n\t\tcout << \"copy constructor!\" << endl;\n\t\tmAge = person.mAge;\n\t}\n\t~Person(){\n\t\tcout << \"destructor!\" << endl;\n\t}\npublic:\n\tint mAge;\n};\n//1. 旧对象初始化新对象\nvoid test01(){\n\n\tPerson p(10);\n\tPerson p1(p);\n\tPerson p2 = Person(p);\n\tPerson p3 = p; // 相当于Person p2 = Person(p);\n}\n\n//2. 传递的参数是普通对象，函数参数也是普通对象，传递将会调用拷贝构造\nvoid doBussiness(Person p){}\n\nvoid test02(){\n\tPerson p(10);\n\tdoBussiness(p);\n}\n\n//3. 函数返回局部对象\nPerson MyBusiness(){\n\tPerson p(10);\n\tcout << \"局部p:\" << (int*)&p << endl;\n\treturn p;\n}\nvoid test03(){\n\t//vs release、qt下没有调用拷贝构造函数\n\t//vs debug下调用一次拷贝构造函数\n\tPerson p = MyBusiness();\n\tcout << \"局部p:\" << (int*)&p << endl;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Person{\npublic:\n\tPerson(char* name,int age){\n\t\tpName = (char*)malloc(strlen(name) + 1);\n\t\tstrcpy(pName,name);\n\t\tmAge = age;\n\t}\n\t//增加拷贝构造函数\n\tPerson(const Person& person){\n\t\tpName = (char*)malloc(strlen(person.pName) + 1);\n\t\tstrcpy(pName, person.pName);\n\t\tmAge = person.mAge;\n\t}\n\t~Person(){\n\t\tif (pName != NULL){\n\t\t\tfree(pName);\n\t\t}\n\t}\nprivate:\n\tchar* pName;\n\tint mAge;\n};\n\nvoid test(){\n\tPerson p1(\"Edward\",30);\n\t//用对象p1初始化对象p2,调用c++提供的默认拷贝构造函数\n\tPerson p2 = p1;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Person{\npublic:\n#if 0\n\t//传统方式初始化\n\tPerson(int a,int b,int c){\n\t\tmA = a;\n\t\tmB = b;\n\t\tmC = c;\n\t}\n#endif\n\t//初始化列表方式初始化\n\tPerson(int a, int b, int c):mA(a),mB(b),mC(c){}\n\tvoid PrintPerson(){\n\t\tcout << \"mA:\" << mA << endl;\n\t\tcout << \"mB:\" << mB << endl;\n\t\tcout << \"mC:\" << mC << endl;\n\t}\nprivate:\n\tint mA;\n\tint mB;\n\tint mC;\n};"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//汽车类\nclass Car{\npublic:\n\tCar(){\n\t\tcout << \"Car 默认构造函数!\" << endl;\n\t\tmName = \"大众汽车\";\n\t}\n\tCar(string name){\n\t\tcout << \"Car 带参数构造函数!\" << endl;\n\t\tmName = name;\n\t}\n\t~Car(){\n\t\tcout << \"Car 析构函数!\" << endl;\n\t}\npublic:\n\tstring mName;\n};\n\n//拖拉机\nclass Tractor{\npublic:\n\tTractor(){\n\t\tcout << \"Tractor 默认构造函数!\" << endl;\n\t\tmName = \"爬土坡专用拖拉机\";\n\t}\n\tTractor(string name){\n\t\tcout << \"Tractor 带参数构造函数!\" << endl;\n\t\tmName = name;\n\t}\n\t~Tractor(){\n\t\tcout << \"Tractor 析构函数!\" << endl;\n\t}\npublic:\n\tstring mName;\n};\n\n//人类\nclass Person{\npublic:\n#if 1\n\t//类mCar不存在合适的构造函数\n\tPerson(string name){\n\t\tmName = name;\n\t}\n#else\n\t//初始化列表可以指定调用构造函数\n\tPerson(string carName, string tracName, string name) : mTractor(tracName), mCar(carName), mName(name){\n\t\tcout << \"Person 构造函数!\" << endl;\n\t}\n#endif\n\t\n\tvoid GoWorkByCar(){\n\t\tcout << mName << \"开着\" << mCar.mName << \"去上班!\" << endl;\n\t}\n\tvoid GoWorkByTractor(){\n\t\tcout << mName << \"开着\" << mTractor.mName << \"去上班!\" << endl;\n\t}\n\t~Person(){\n\t\tcout << \"Person 析构函数!\" << endl;\n\t}\nprivate:\n\tstring mName;\n\tCar mCar;\n\tTractor mTractor;\n};\n\nvoid test(){\n\t//Person person(\"宝马\", \"东风拖拉机\", \"赵四\");\n\tPerson person(\"刘能\");\n\tperson.GoWorkByCar();\n\tperson.GoWorkByTractor();\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class MyString{\npublic:\n\texplicit MyString(int n){\n\t\tcout << \"MyString(int n)!\" << endl;\n\t}\n\tMyString(const char* str){\n\t\tcout << \"MyString(const char* str)\" << endl;\n\t}\n};\n\nint main(){\n\n\t//给字符串赋值？还是初始化？\n\t//MyString str1 = 1; \n\tMyString str2(10);\n\n\t//寓意非常明确，给字符串赋值\n\tMyString str3 = \"abcd\";\n\tMyString str4(\"abcd\");\n\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Person{\npublic:\n\tPerson(){\n\t\tmAge = 20;\n\t\tpName = (char*)malloc(strlen(\"john\")+1);\n\t\tstrcpy(pName, \"john\");\n\t}\n\tvoid Init(){\n\t\tmAge = 20;\n\t\tpName = (char*)malloc(strlen(\"john\")+1);\n\t\tstrcpy(pName, \"john\");\n\t}\n\tvoid Clean(){\n\t\tif (pName != NULL){\n\t\t\tfree(pName);\n\t\t}\n\t}\npublic:\n\tint mAge;\n\tchar* pName;\n};\nint main(){\n\n\t//分配内存\n\tPerson* person = (Person*)malloc(sizeof(Person));\n\tif(person == NULL){\n\t\treturn 0;\n\t}\n\t//调用初始化函数\n\tperson->Init();\n\t//清理对象\n\tperson->Clean();\n\t//释放person对象\n\tfree(person);\n\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "Person* person = new Person;\n相当于:\nPerson* person = (Person*)malloc(sizeof(Person));\n\tif(person == NULL){\n\t\treturn 0;\n\t}\nperson->Init(); 构造函数"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Person{\npublic:\n\tPerson(){\n\t\tcout << \"无参构造函数!\" << endl;\n\t\tpName = (char*)malloc(strlen(\"undefined\") + 1);\n\t\tstrcpy(pName, \"undefined\");\n\t\tmAge = 0;\n\t}\n\tPerson(char* name, int age){\n\t\tcout << \"有参构造函数!\" << endl;\n\t\tpName = (char*)malloc(strlen(name) + 1);\n\t\tstrcpy(pName, name);\n\t\tmAge = age;\n\t}\n\tvoid ShowPerson(){\n\t\tcout << \"Name:\" << pName << \" Age:\" << mAge << endl;\n\t}\n\t~Person(){\n\t\tcout << \"析构函数!\" << endl;\n\t\tif (pName != NULL){\n\t\t\tdelete pName;\n\t\t\tpName = NULL;\n\t\t}\n\t}\npublic:\n\tchar* pName;\n\tint mAge;\n};\n\nvoid test(){\n\tPerson* person1 = new Person;\n\tPerson* person2 = new Person(\"John\",33);\n\n\tperson1->ShowPerson();\n\tperson2->ShowPerson();\n\n\tdelete person1;\n\tdelete person2;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//创建字符数组\nchar* pStr = new char[100];\n//创建整型数组\nint* pArr1 = new int[100]; \n//创建整型数组并初始化\nint* pArr2 = new int[10]{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };\n\n//释放数组内存\ndelete[] pStr;\ndelete[] pArr1;\ndelete[] pArr2;"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Person{\npublic:\n\tPerson(){\n\t\tpName = (char*)malloc(strlen(\"undefined\") + 1);\n\t\tstrcpy(pName, \"undefined\");\n\t\tmAge = 0;\n\t}\n\tPerson(char* name, int age){\n\t\tpName = (char*)malloc(sizeof(name));\n\t\tstrcpy(pName, name);\n\t\tmAge = age;\n\t}\n\t~Person(){\n\t\tif (pName != NULL){\n\t\t\tdelete pName;\n\t\t}\n\t}\npublic:\n\tchar* pName;\n\tint mAge;\n};\n\nvoid test(){\n\t//栈聚合初始化\n\tPerson person[] = { Person(\"john\", 20), Person(\"Smith\", 22) };\n\tcout << person[1].pName << endl;\n    //创建堆上对象数组必须提供构造函数\n\tPerson* workers = new Person[20];\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Person{\npublic:\n\tPerson(char* name, int age){\n\t\tpName = (char*)malloc(sizeof(name));\n\t\tstrcpy(pName,name);\n\t\tmAge = age;\n\t}\n\t~Person(){\n\t\tif (pName != NULL){\n\t\t\tdelete pName;\n\t\t}\n\t}\npublic:\n\tchar* pName;\n\tint mAge;\n};\n\nvoid test(){\n\tvoid* person = new Person(\"john\",20);\n\tdelete person;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Person{\npublic:\n\t//类的静态成员属性\n\tstatic int sNum;\nprivate:\n\tstatic int sOther;\n};\n\n//类外初始化，初始化时不加static\nint Person::sNum = 0;\nint Person::sOther = 0;\nint main(){\n\n\n\t//1. 通过类名直接访问\n\tPerson::sNum = 100;\n\tcout << \"Person::sNum:\" << Person::sNum << endl;\n\n\t//2. 通过对象访问\n\tPerson p1, p2;\n\tp1.sNum = 200;\n\n\tcout << \"p1.sNum:\" << p1.sNum << endl;\n\tcout << \"p2.sNum:\" << p2.sNum << endl;\n\n\t//3. 静态成员也有访问权限，类外不能访问私有成员\n\t//cout << \"Person::sOther:\" << Person::sOther << endl;\n\tPerson p3;\n\t//cout << \"p3.sOther:\" << p3.sOther << endl;\n\n\tsystem(\"pause\");\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Person{\npublic:\n\t//普通成员函数可以访问static和non-static成员属性\n\tvoid changeParam1(int param){\n\t\tmParam = param;\n\t\tsNum = param;\n\t}\n\t//静态成员函数只能访问static成员属性\n\tstatic void changeParam2(int param){\n\t\t//mParam = param; //无法访问\n\t\tsNum = param;\n\t}\nprivate:\n\tstatic void changeParam3(int param){\n\t\t//mParam = param; //无法访问\n\t\tsNum = param;\n\t}\npublic:\n\tint mParam;\n\tstatic int sNum;\n};\n\n//静态成员属性类外初始化\nint Person::sNum = 0;\n\nint main(){\n\n\t//1. 类名直接调用\n\tPerson::changeParam2(100);\n\n\t//2. 通过对象调用\n\tPerson p;\n\tp.changeParam2(200);\n\n\t//3. 静态成员函数也有访问权限\n\t//Person::changeParam3(100); //类外无法访问私有静态成员函数\n\t//Person p1;\n\t//p1.changeParam3(200);\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Person{\npublic:\n\t//static const int mShare = 10;\n\tconst static int mShare = 10; //只读区，不可修改\n};\nint main(){\n\n\tcout << Person::mShare << endl;\n\t//Person::mShare = 20;\n\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Printer{\npublic:\n\tstatic Printer* getInstance(){ return pPrinter;}\n\tvoid PrintText(string text){\n\t\tcout << \"打印内容:\" << text << endl;\n\t\tcout << \"已打印次数:\" << mTimes << endl;\n\t\tcout << \"--------------\" << endl;\n\t\tmTimes++;\n\t}\nprivate:\n\tPrinter(){ mTimes = 0; }\n\tPrinter(const Printer&){}\nprivate:\n\tstatic Printer* pPrinter;\n\tint mTimes;\n};\n\nPrinter* Printer::pPrinter = new Printer;\n\nvoid test(){\n\tPrinter* printer = Printer::getInstance();\n\tprinter->PrintText(\"离职报告!\");\n\tprinter->PrintText(\"入职合同!\");\n\tprinter->PrintText(\"提交代码!\");\n}"
    }
  ],
  "58954456": [
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class MyClass01{\npublic:\n\tint mA;\n};\n\nclass MyClass02{\npublic:\n\tint mA;\n\tstatic int sB;\n};\n\nclass MyClass03{\npublic:\n\tvoid printMyClass(){\n\t\tcout << \"hello world!\" << endl;\n\t}\npublic:\n\tint mA;\n\tstatic int sB;\n};\n\nclass MyClass04{\npublic:\n\tvoid printMyClass(){\n\t\tcout << \"hello world!\" << endl;\n\t}\n\tstatic void ShowMyClass(){\n\t\tcout << \"hello world！\" << endl;\n\t}\npublic:\n\tint mA;\n\tstatic int sB;\n};\n\nint main(){\n\n\tMyClass01 mclass01;\n\tMyClass02 mclass02;\n\tMyClass03 mclass03;\n\tMyClass04 mclass04;\n\n\tcout << \"MyClass01:\" << sizeof(mclass01) << endl; //4\n\t//静态数据成员并不保存在类对象中\n\tcout << \"MyClass02:\" << sizeof(mclass02) << endl; //4\n\t//非静态成员函数不保存在类对象中\n\tcout << \"MyClass03:\" << sizeof(mclass03) << endl; //4\n\t//静态成员函数也不保存在类对象中\n\tcout << \"MyClass04:\" << sizeof(mclass04) << endl; //4\n\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Person{\npublic:\n\t//1. 当形参名和成员变量名一样时，this指针可用来区分\n\tPerson(string name,int age){\n\t\t//name = name;\n\t\t//age = age; //输出错误\n\t\tthis->name = name;\n\t\tthis->age = age;\n\t}\n\t//2. 返回对象本身的引用\n\t//重载赋值操作符\n\t//其实也是两个参数，其中隐藏了一个this指针\n\tPerson PersonPlusPerson(Person& person){\n\t\tstring newname = this->name + person.name;\n\t\tint newage = this->age + person.age;\n\t\tPerson newperson(newname, newage);\n\t\treturn newperson;\n\t}\n\tvoid ShowPerson(){\n\t\tcout << \"Name:\" << name << \" Age:\" << age << endl;\n\t}\npublic:\n\tstring name;\n\tint age;\n};\n\n//3. 成员函数和全局函数(Perosn对象相加)\nPerson PersonPlusPerson(Person& p1,Person& p2){\n\tstring newname = p1.name + p2.name;\n\tint newage = p1.age + p2.age;\n\tPerson newperson(newname,newage);\n\treturn newperson;\n}\n\nint main(){\n\n\tPerson person(\"John\",100);\n\tperson.ShowPerson();\n\n\tcout << \"---------\" << endl;\n\tPerson person1(\"John\",20);\n\tPerson person2(\"001\", 10);\n\t//1.全局函数实现两个对象相加\n\tPerson person3 = PersonPlusPerson(person1, person2);\n\tperson1.ShowPerson();\n\tperson2.ShowPerson();\n\tperson3.ShowPerson();\n\t//2. 成员函数实现两个对象相加\n\tPerson person4 = person1.PersonPlusPerson(person2);\n\tperson4.ShowPerson();\n\n\tsystem(\"pause\");\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//const修饰成员函数\nclass Person{\npublic:\n\tPerson(){\n\t\tthis->mAge = 0;\n\t\tthis->mID = 0;\n\t}\n\t//在函数括号后面加上const,修饰成员变量不可修改,除了mutable变量\n\tvoid sonmeOperate() const{\n\t\t//this->mAge = 200; //mAge不可修改\n\t\tthis->mID = 10;\n\t}\n\tvoid ShowPerson(){\n\t\tcout << \"ID:\" << mID << \" mAge:\" << mAge << endl;\n\t}\nprivate:\n\tint mAge;\n\tmutable int mID;\n};\n\nint main(){\n\n\tPerson person;\n\tperson.sonmeOperate();\n\tperson.ShowPerson();\n\n\tsystem(\"pause\");\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Person{\npublic:\n\tPerson(){\n\t\tthis->mAge = 0;\n\t\tthis->mID = 0;\n\t}\n\tvoid ChangePerson() const{\n\t\tmAge = 100;\n\t\tmID = 100;\n\t}\n\tvoid ShowPerson(){\n        this->mAge = 1000;\n\t\tcout << \"ID:\" << this->mID << \" Age:\" << this->mAge << endl;\n\t}\n\npublic:\n\tint mAge;\n\tmutable int mID;\n};\n\nvoid test(){\t\n\tconst Person person;\n\t//1. 可访问数据成员\n\tcout << \"Age:\" << person.mAge << endl;\n\t//person.mAge = 300; //不可修改\n\tperson.mID = 1001; //但是可以修改mutable修饰的成员变量\n\t//2. 只能访问const修饰的函数\n\t//person.ShowPerson();\n\tperson.ChangePerson();\n}"
    }
  ],
  "58954457": [
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Building;\n//友元类\nclass MyFriend{\npublic:\n\t//友元成员函数\n\tvoid LookAtBedRoom(Building& building);\n\tvoid PlayInBedRoom(Building& building);\n};\nclass Building{\n\t//全局函数做友元函数\n\tfriend void CleanBedRoom(Building& building);\n#if 0\n\t//成员函数做友元函数\n\tfriend void MyFriend::LookAtBedRoom(Building& building);\n\tfriend void MyFriend::PlayInBedRoom(Building& building);\n#else\t\n\t//友元类\n\tfriend class MyFriend;\n#endif\npublic:\n\tBuilding();\npublic:\n\tstring mSittingRoom;\nprivate:\n\tstring mBedroom;\n};\n\nvoid MyFriend::LookAtBedRoom(Building& building){\n\tcout << \"我的朋友参观\" << building.mBedroom << endl;\n}\nvoid MyFriend::PlayInBedRoom(Building& building){\n\tcout << \"我的朋友玩耍在\" << building.mBedroom << endl;\n}\n\n//友元全局函数\nvoid CleanBedRoom(Building& building){\n\tcout << \"友元全局函数访问\" << building.mBedroom << endl;\n}\n\nBuilding::Building(){\n\tthis->mSittingRoom = \"客厅\";\n\tthis->mBedroom = \"卧室\";\n}\n\nint main(){\n\n\tBuilding building;\n\tMyFriend myfriend;\n\n\tCleanBedRoom(building);\n\tmyfriend.LookAtBedRoom(building);\n\tmyfriend.PlayInBedRoom(building);\n\n\tsystem(\"pause\");\n\treturn EXIT_SUCCESS;\n}"
    }
  ],
  "58954458": [
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Person{\n\tfriend ostream& operator<<(ostream& os, Person& person);\npublic:\n\tPerson(int id,int age){\n\t\tmID = id;\n\t\tmAge = age;\n\t}\nprivate:\n\tint mID;\n\tint mAge;\n};\n\nostream& operator<<(ostream& os, Person& person){\n\tos << \"ID:\" << person.mID << \" Age:\" << person.mAge;\n\treturn os;\n}\n\nint main(){\n\n\tPerson person(1001, 30);\n\t//cout << person; //cout.operator+(person)\n\tcout << person << \" | \" << endl;\n\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Complex{\n\tfriend ostream& operator<<(ostream& os,Complex& complex){\n\t\tos << \"A:\" << complex.mA << \" B:\" << complex.mB << endl;\n\t\treturn os;\n\t}\npublic:\n\tComplex(){\n\t\tmA = 0;\n\t\tmB = 0;\n\t}\n\t//重载前置++\n\tComplex& operator++(){\n\t\tmA++;\n\t\tmB++;\n\t\treturn *this;\n\t}\n\t//重载后置++\n\tComplex operator++(int){\t\n\t\tComplex temp;\n\t\ttemp.mA = this->mA;\n\t\ttemp.mB = this->mB;\n\t\tmA++;\n\t\tmB++;\n\t\treturn temp;\n\t}\n\t//前置--\n\tComplex& operator--(){\n\t\tmA--;\n\t\tmB--;\n\t\treturn *this;\n\t}\n\t//后置--\n\tComplex operator--(int){\n\t\tComplex temp;\n\t\ttemp.mA = mA;\n\t\ttemp.mB = mB;\n\t\tmA--;\n\t\tmB--;\n\t\treturn temp;\n\t}\n\tvoid ShowComplex(){\n\t\tcout << \"A:\" << mA << \" B:\" << mB << endl;\n\t}\nprivate:\n\tint mA;\n\tint mB;\n};\n\nvoid test(){\n\tComplex complex;\n\tcomplex++;\n\tcout << complex;\n\t++complex;\n\tcout << complex;\n\n\tComplex ret = complex++;\n\tcout << ret;\n\tcout << complex;\n\n\tcout << \"------\" << endl;\n\tret--;\n\t--ret;\n\tcout << \"ret:\" << ret;\n\tcomplex--;\n\t--complex;\n\tcout << \"complex:\" << complex;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Person{\npublic:\n\tPerson(int param){\n\t\tthis->mParam = param;\n\t}\n\tvoid PrintPerson(){\n\t\tcout << \"Param:\" << mParam << endl;\n\t}\nprivate:\n\tint mParam;\n};\n\nclass SmartPointer{\npublic:\n\tSmartPointer(Person* person){\n\t\tthis->pPerson = person;\n\t}\n\t//重载指针的->、*操作符\n\tPerson* operator->(){\n\t\treturn pPerson;\n\t}\n\tPerson& operator*(){\n\t\treturn *pPerson;\n\t}\n\t~SmartPointer(){\n\t\tif (pPerson != NULL){\n\t\t\tdelete pPerson;\n\t\t}\n\t}\npublic:\n\tPerson* pPerson;\n};\n\nvoid test01(){\n\t\n\t//Person* person = new Person(100);\n\t//如果忘记释放，那么就会造成内存泄漏\n\n\tSmartPointer pointer(new Person(100));\n\tpointer->PrintPerson();\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Person{\n\tfriend ostream& operator<<(ostream& os,const Person& person){\n\t\tos << \"ID:\" << person.mID << \" Age:\" << person.mAge << endl;\n\t\treturn os;\n\t}\npublic:\n\tPerson(int id,int age){\n\t\tthis->mID = id;\n\t\tthis->mAge = age;\n\t}\n\t//重载赋值运算符\n\tPerson& operator=(const Person& person){\n\t\tthis->mID = person.mID;\n\t\tthis->mAge = person.mAge;\n\t\treturn *this;\n\t}\nprivate:\n\tint mID;\n\tint mAge;\n};\n\n//1. =号混淆的地方\nvoid test01(){\n\tPerson person1(10, 20);\n\tPerson person2 = person1; //调用拷贝构造\n\t//如果一个对象还没有被创建，则必须初始化，也就是调用构造函数\n\t//上述例子由于person2还没有初始化，所以会调用构造函数\n\t//由于person2是从已有的person1来创建的，所以只有一个选择\n\t//就是调用拷贝构造函数\n\tperson2 = person1; //调用operator=函数\n\t//由于person2已经创建，不需要再调用构造函数，这时候调用的是重载的赋值运算符\n}\n//2. 赋值重载案例\nvoid test02(){\n\tPerson person1(20, 20);\n\tPerson person2(30, 30);\n\tcout << \"person1:\" << person1;\n\tcout << \"person2:\" << person2;\n\tperson2 = person1;\n\tcout << \"person2:\" << person2;\n}\n//常见错误，当准备给两个相同对象赋值时，应该首先检查一下这个对象是否对自身赋值了\n//对于本例来讲，无论如何执行这些赋值运算都是无害的，但如果对类的实现进行修改，那么将会出现差异；\n//3. 类中指针\nclass Person2{\n\tfriend ostream& operator<<(ostream& os, const Person2& person){\n\t\tos << \"Name:\" << person.pName << \" ID:\" << person.mID << \" Age:\" << person.mAge << endl;\n\t\treturn os;\n\t}\npublic:\n\tPerson2(char* name,int id, int age){\n\t\tthis->pName = new char[strlen(name) + 1];\n\t\tstrcpy(this->pName, name);\n\t\tthis->mID = id;\n\t\tthis->mAge = age;\n\t}\n#if 1\n\t//重载赋值运算符\n\tPerson2& operator=(const Person2& person){\n\n\t\t//注意:由于当前对象已经创建完毕，那么就有可能pName指向堆内存\n\t\t//这个时候如果直接赋值，会导致内存没有及时释放\n\t\tif (this->pName != NULL){\n\t\t\tdelete[] this->pName;\n\t\t}\n\n\t\tthis->pName = new char[strlen(person.pName) + 1];\n\t\tstrcpy(this->pName,person.pName);\n\t\tthis->mID = person.mID;\n\t\tthis->mAge = person.mAge;\n\t\treturn *this;\n\t}\n#endif\n\t//析构函数\n\t~Person2(){\n\t\tif (this->pName != NULL){\n\t\t\tdelete[] this->pName;\n\t\t}\n\t}\nprivate:\n\tchar* pName;\n\tint mID;\n\tint mAge;\n};\n\nvoid test03(){\n\tPerson2 person1(\"John\",20, 20);\n\tPerson2 person2(\"Edward\",30, 30);\n\tcout << \"person1:\" << person1;\n\tcout << \"person2:\" << person2;\n\tperson2 = person1;\n\tcout << \"person2:\" << person2;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Complex{\npublic:\n\tComplex(char* name,int id,int age){\n\t\tthis->pName = new char[strlen(name) + 1];\n\t\tstrcpy(this->pName, name);\n\t\tthis->mID = id;\n\t\tthis->mAge = age;\n\t}\n\t//重载==号操作符\n\tbool operator==(const Complex& complex){\n\t\tif (strcmp(this->pName,complex.pName) == 0 && \n\t\t    this->mID == complex.mID && \n\t\t\tthis->mAge == complex.mAge){\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\t//重载!=操作符\n\tbool operator!=(const Complex& complex){\n\t\tif (strcmp(this->pName, complex.pName) != 0 || \n\t\t    this->mID != complex.mID || \n\t\t\tthis->mAge != complex.mAge){\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\t~Complex(){\n\t\tif (this->pName != NULL){\n\t\t\tdelete[] this->pName;\n\t\t}\n\t}\nprivate:\n\tchar* pName;\n\tint mID;\n\tint mAge;\n};\nvoid test(){\n\tComplex complex1(\"aaa\", 10, 20);\n\tComplex complex2(\"bbb\", 10, 20);\n\tif (complex1 == complex2){ cout << \"相等!\" << endl; }\n\tif (complex1 != complex2){ cout << \"不相等!\" << endl; }\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Complex{\npublic:\n\tint Add(int x,int y){\n\t\treturn x + y;\n\t}\n\tint operator()(int x,int y){\n\t\treturn x + y;\n\t}\n};\nvoid test01(){\n\tComplex complex;\n\tcout << complex.Add(10,20) << endl;\n\t//对象当做函数来调用\n\tcout << complex(10, 20) << endl;\n}"
    }
  ],
  "58954461": [
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "网页类\nclass IndexPage{\npublic:\n\t//网页头部\n\tvoid Header(){\n\t\tcout << \"网页头部!\" << endl;\n\t}\n\t//网页左侧菜单\n\tvoid LeftNavigation(){\n\t\tcout << \"左侧导航菜单!\" << endl;\n\t}\n\t//网页主体部分\n\tvoid MainBody(){\n\t\tcout << \"首页网页主题内容!\" << endl;\n\t}\n\t//网页底部\n\tvoid Footer(){\n\t\tcout << \"网页底部!\" << endl;\n\t}\nprivate:\n\tstring mTitle; //网页标题\n};\n\n#if 0\n//如果不使用继承，那么定义新闻页类，需要重新写一遍已经有的代码\nclass NewsPage{\npublic:\n\t//网页头部\n\tvoid Header(){\n\t\tcout << \"网页头部!\" << endl;\n\t}\n\t//网页左侧菜单\n\tvoid LeftNavigation(){\n\t\tcout << \"左侧导航菜单!\" << endl;\n\t}\n\t//网页主体部分\n\tvoid MainBody(){\n\t\tcout << \"新闻网页主体内容!\" << endl;\n\t}\n\t//网页底部\n\tvoid Footer(){\n\t\tcout << \"网页底部!\" << endl;\n\t}\nprivate:\n\tstring mTitle; //网页标题\n};\n\nvoid test(){\n\tNewsPage* newspage = new NewsPage;\n\tnewspage->Header();\n\tnewspage->MainBody();\n\tnewspage->LeftNavigation();\n\tnewspage->Footer();\n}\n#else\n//使用继承，可以复用已有的代码，新闻业除了主体部分不一样，其他都是一样的\nclass NewsPage : public IndexPage{\npublic:\n\t//网页主体部分\n\tvoid MainBody(){\n\t\tcout << \"新闻网页主主体内容!\" << endl;\n\t}\n};\nvoid test(){\n\tNewsPage* newspage = new NewsPage;\n\tnewspage->Header();\n\tnewspage->MainBody();\n\tnewspage->LeftNavigation();\n\tnewspage->Footer();\n}\n#endif\nint main(){\n\n\ttest();\n\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//基类\nclass A{\npublic:\n\tint mA;\nprotected:\n\tint mB;\nprivate:\n\tint mC;\n};\n\n//1. 公有(public)继承\nclass B : public A{\npublic:\n\tvoid PrintB(){\n\t\tcout << mA << endl; //可访问基类public属性\n\t\tcout << mB << endl; //可访问基类protected属性\n\t\t//cout << mC << endl; //不可访问基类private属性\n\t}  \n};\nclass SubB : public B{\n\tvoid PrintSubB(){\n\t\tcout << mA << endl; //可访问基类public属性\n\t\tcout << mB << endl; //可访问基类protected属性\n\t\t//cout << mC << endl; //不可访问基类private属性\n\t}\n};\nvoid test01(){\n\n\tB b;\n\tcout << b.mA << endl; //可访问基类public属性\n\t//cout << b.mB << endl; //不可访问基类protected属性\n\t//cout << b.mC << endl; //不可访问基类private属性\n}\n\n//2. 私有(private)继承\nclass C : private A{\npublic:\n\tvoid PrintC(){\n\t\tcout << mA << endl; //可访问基类public属性\n\t\tcout << mB << endl; //可访问基类protected属性\n\t\t//cout << mC << endl; //不可访问基类private属性\n\t}\n};\nclass SubC : public C{\n\tvoid PrintSubC(){\n\t\t//cout << mA << endl; //不可访问基类public属性\n\t\t//cout << mB << endl; //不可访问基类protected属性\n\t\t//cout << mC << endl; //不可访问基类private属性\n\t}\n};\nvoid test02(){\n\tC c;\n\t//cout << c.mA << endl; //不可访问基类public属性\n\t//cout << c.mB << endl; //不可访问基类protected属性\n\t//cout << c.mC << endl; //不可访问基类private属性\n}\n//3. 保护(protected)继承\nclass D : protected A{\npublic:\n\tvoid PrintD(){\n\t\tcout << mA << endl; //可访问基类public属性\n\t\tcout << mB << endl; //可访问基类protected属性\n\t\t//cout << mC << endl; //不可访问基类private属性\n\t}\n};\nclass SubD : public D{\n\tvoid PrintD(){\n\t\tcout << mA << endl; //可访问基类public属性\n\t\tcout << mB << endl; //可访问基类protected属性\n\t\t//cout << mC << endl; //不可访问基类private属性\n\t}\n};\nvoid test03(){\n\tD d;\n\t//cout << d.mA << endl; //不可访问基类public属性\n\t//cout << d.mB << endl; //不可访问基类protected属性\n\t//cout << d.mC << endl; //不可访问基类private属性\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Aclass{\npublic:\n\tint mA;\n\tint mB;\n};\nclass Bclass : public Aclass{\npublic:\n\tint mC;\n};\nclass Cclass : public Bclass{\npublic:\n\tint mD;\n};\nvoid test(){\n\tcout << \"A size:\" << sizeof(Aclass) << endl;\n\tcout << \"B size:\" << sizeof(Bclass) << endl;\n\tcout << \"C size:\" << sizeof(Cclass) << endl;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class A{\npublic:\n\tA(){\n\t\tcout << \"A类构造函数!\" << endl;\n\t}\n\t~A(){\n\t\tcout << \"A类析构函数!\" << endl;\n\t}\n};\n\nclass B : public A{\npublic:\n\tB(){\n\t\tcout << \"B类构造函数!\" << endl;\n\t}\n\t~B(){\n\t\tcout << \"B类析构函数!\" << endl;\n\t}\n};\n\nclass C : public B{\npublic:\n\tC(){\n\t\tcout << \"C类构造函数!\" << endl;\n\t}\n\t~C(){\n\t\tcout << \"C类析构函数!\" << endl;\n\t}\n};\n\nvoid test(){\n\tC c;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class D{\npublic:\n\tD(){\n\t\tcout << \"D类构造函数!\" << endl;\n\t}\n\t~D(){\n\t\tcout << \"D类析构函数!\" << endl;\n\t}\n};\nclass A{\npublic:\n\tA(){\n\t\tcout << \"A类构造函数!\" << endl;\n\t}\n\t~A(){\n\t\tcout << \"A类析构函数!\" << endl;\n\t}\n};\nclass B : public A{\npublic:\n\tB(){\n\t\tcout << \"B类构造函数!\" << endl;\n\t}\n\t~B(){\n\t\tcout << \"B类析构函数!\" << endl;\n\t}\n};\nclass C : public B{\npublic:\n\tC(){\n\t\tcout << \"C类构造函数!\" << endl;\n\t}\n\t~C(){\n\t\tcout << \"C类析构函数!\" << endl;\n\t}\npublic:\n\tD c;\n};\nvoid test(){\n\tC c;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Base{\npublic:\n\tBase():mParam(0){}\n\tvoid Print(){ cout << mParam << endl; }\npublic:\n\tint mParam;\n};\n\nclass Derived : public Base{\npublic:\n\tDerived():mParam(10){}\n\tvoid Print(){\n\t\t//在派生类中使用和基类的同名成员,显示使用类名限定符\n\t\tcout << Base::mParam << endl;\n\t\tcout << mParam << endl;\n\t}\n\t//返回基类重名成员\n\tint& getBaseParam(){ return  Base::mParam; }\npublic:\n\tint mParam;\n};\n\nint main(){\n\n\tDerived derived;\n\t//派生类和基类成员属性重名，子类访问成员默认是子类成员\n\tcout << derived.mParam << endl; //10\n\tderived.Print();\n\t//类外如何获得基类重名成员属性\n\tderived.getBaseParam() = 100;\n\tcout << \"Base:mParam:\" << derived.getBaseParam() << endl;\n\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Base{\npublic:\n\tvoid func1(){\n\t\tcout << \"Base::void func1()\" << endl;\n\t};\n\tvoid func1(int param){\n\t\tcout << \"Base::void func1(int param)\" << endl;\n\t}\n\tvoid myfunc(){\n\t\tcout << \"Base::void myfunc()\" << endl;\n\t}\n};\nclass Derived1 : public Base{\npublic:\n\tvoid myfunc(){\n\t\tcout << \"Derived1::void myfunc()\" << endl;\n\t}\n};\nclass Derived2 : public Base{\npublic:\n\t//改变成员函数的参数列表\n\tvoid func1(int param1, int param2){\n\t\tcout << \"Derived2::void func1(int param1,int param2)\" << endl;\n\t};\n};\nclass Derived3 : public Base{\npublic:\n\t//改变成员函数的返回值\n\tint func1(int param){\n\t\tcout << \"Derived3::int func1(int param)\" << endl;\n\t\treturn 0;\n\t}\n};\nint main(){\n\n\tDerived1 derived1;\n\tderived1.func1();\n\tderived1.func1(20);\n\tderived1.myfunc();\n\tcout << \"-------------\" << endl;\n\tDerived2 derived2;\n\t//derived2.func1();  //func1被隐藏\n\t//derived2.func1(20); //func2被隐藏\n\tderived2.func1(10,20); //重载func1之后，基类的函数被隐藏\n\tderived2.myfunc();\n\tcout << \"-------------\" << endl;\n\tDerived3 derived3;\n\t//derived3.func1();  没有重新定义的重载版本被隐藏\n\tderived3.func1(20);\n\tderived3.myfunc();\n\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Base{\npublic:\n\tstatic int getNum(){ return sNum; }\n\tstatic int getNum(int param){\n\t\treturn sNum + param;\n\t}\npublic:\n\tstatic int sNum;\n};\nint Base::sNum = 10;\n\nclass Derived : public Base{\npublic:\n\tstatic int sNum; //基类静态成员属性将被隐藏\n#if 0\n\t//重定义一个函数，基类中重载的函数被隐藏\n\tstatic int getNum(int param1, int param2){\n\t\treturn sNum + param1 + param2;\n\t}\n#else\n\t//改变基类函数的某个特征，返回值或者参数个数，将会隐藏基类重载的函数\n\tstatic void getNum(int param1, int param2){\n\t\tcout <<  sNum + param1 + param2 << endl;\n\t}\n#endif\n};\nint Derived::sNum = 20;"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Base1{\npublic:\n\tvoid func1(){ cout << \"Base1::func1\" << endl; }\n};\nclass Base2{\npublic:\n\tvoid func1(){ cout << \"Base2::func1\" << endl; }\n\tvoid func2(){ cout << \"Base2::func2\" << endl; }\n};\n//派生类继承Base1、Base2\nclass Derived : public Base1, public Base2{};\nint main(){\n\n\tDerived derived;\n\t//func1是从Base1继承来的还是从Base2继承来的？\n\t//derived.func1(); \n\tderived.func2();\n\n\t//解决歧义:显示指定调用那个基类的func1\n\tderived.Base1::func1(); \n\tderived.Base2::func1();\n\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class BigBase{\npublic:\n\tBigBase(){ mParam = 0; }\n\tvoid func(){ cout << \"BigBase::func\" << endl; }\npublic:\n\tint mParam;\n};\n\nclass Base1 : public BigBase{};\nclass Base2 : public BigBase{};\nclass Derived : public Base1, public Base2{};\n\nint main(){\n\n\tDerived derived;\n\t//1. 对“func”的访问不明确\n\t//derived.func();\n\t//cout << derived.mParam << endl;\n\tcout << \"derived.Base1::mParam:\" << derived.Base1::mParam << endl;\n\tcout << \"derived.Base2::mParam:\" << derived.Base2::mParam << endl;\n\n\t//2. 重复继承\n\tcout << \"Derived size:\" << sizeof(Derived) << endl; //8\n\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class BigBase{\npublic:\n\tBigBase(){ mParam = 0; }\n\tvoid func(){ cout << \"BigBase::func\" << endl; }\npublic:\n\tint mParam;\n};\n\nclass Base1 : virtual public BigBase{};\nclass Base2 : virtual public BigBase{};\nclass Derived : public Base1, public Base2{};\n\nint main(){\n\n\tDerived derived;\n\t//二义性问题解决\n\tderived.func();\n\tcout << derived.mParam << endl;\n\t//输出结果:12\n\tcout << \"Derived size:\" << sizeof(Derived) << endl;\n\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class BigBase{\npublic:\n\tBigBase(){ mParam = 0; }\n\tvoid func(){ cout << \"BigBase::func\" << endl; }\npublic: int mParam;\n};\n#if 0 //虚继承\nclass Base1 : virtual public BigBase{};\nclass Base2 : virtual public BigBase{};\n#else //普通继承\nclass Base1 :  public BigBase{};\nclass Base2 :  public BigBase{};\n#endif\nclass Derived : public Base1, public Base2{};"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class BigBase{\npublic:\n\tBigBase(int x){mParam = x;}\n\tvoid func(){cout << \"BigBase::func\" << endl;}\npublic:\n\tint mParam;\n};\nclass Base1 : virtual public BigBase{\npublic:\n\tBase1() :BigBase(10){} //不调用BigBase构造\n};\nclass Base2 : virtual public BigBase{\npublic:\n\tBase2() :BigBase(10){} //不调用BigBase构造\n};\n\nclass Derived : public Base1, public Base2{\npublic:\n\tDerived() :BigBase(10){} //调用BigBase构造\n};\n//每一次继承子类中都必须书写初始化语句\nint main(){\n\tDerived derived;\n\treturn EXIT_SUCCESS;\n}"
    }
  ],
  "58954469": [
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//计算器\nclass Caculator{\npublic:\n\tvoid setA(int a){\n\t\tthis->mA = a;\n\t}\n\tvoid setB(int b){\n\t\tthis->mB = b;\n\t}\n\tvoid setOperator(string oper){\n\t\tthis->mOperator = oper;\n\t}\n\tint getResult(){\n\t\t\n\t\tif (this->mOperator == \"+\"){\n\t\t\treturn mA + mB;\n\t\t}\n\t\telse if (this->mOperator == \"-\"){\n\t\t\treturn mA - mB;\n\t\t}\n\t\telse if (this->mOperator == \"*\"){\n\t\t\treturn mA * mB;\n\t\t}\n\t\telse if (this->mOperator == \"/\"){\n\t\t\treturn mA / mB;\n\t\t}\n\t}\nprivate:\n\tint mA;\n\tint mB;\n\tstring mOperator;\n};\n\n//这种程序不利于扩展，维护困难，如果修改功能或者扩展功能需要在源代码基础上修改\n//面向对象程序设计一个基本原则:开闭原则(对修改关闭，对扩展开放)\n\n//抽象基类\nclass AbstractCaculator{\npublic:\n\tvoid setA(int a){\n\t\tthis->mA = a;\n\t}\n\tvirtual void setB(int b){\n\t\tthis->mB = b;\n\t}\n\tvirtual int getResult() = 0;\nprotected:\n\tint mA;\n\tint mB;\n\tstring mOperator;\n};\n\n//加法计算器\nclass PlusCaculator : public AbstractCaculator{\npublic:\n\tvirtual int getResult(){\n\t\treturn mA + mB;\n\t}\n};\n\n//减法计算器\nclass MinusCaculator : public AbstractCaculator{\npublic:\n\tvirtual int getResult(){\n\t\treturn mA - mB;\n\t}\n};\n\n//乘法计算器\nclass MultipliesCaculator : public AbstractCaculator{\npublic:\n\tvirtual int getResult(){\n\t\treturn mA * mB;\n\t}\n};\n\nvoid DoBussiness(AbstractCaculator* caculator){\n\tint a = 10;\n\tint b = 20;\n\tcaculator->setA(a);\n\tcaculator->setB(b);\n\tcout << \"计算结果：\" << caculator->getResult() << endl;\n\tdelete caculator;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Animal{\npublic:\n\tvoid speak(){\n\t\tcout << \"动物在唱歌...\" << endl;\n\t}\n};\n\nclass Dog : public Animal{\npublic:\n\tvoid speak(){\n\t\tcout << \"小狗在唱歌...\" << endl;\n\t}\n};\n\nvoid DoBussiness(Animal& animal){\n\tanimal.speak();\n}\n\nvoid test(){\n\tDog dog;\n\tDoBussiness(dog);\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Animal{\npublic:\n\tvirtual void speak(){\n\t\tcout << \"动物在唱歌...\" << endl;\n\t}\n};\nclass Dog : public Animal{\npublic:\n\tvirtual void speak(){\n\t\tcout << \"小狗在唱歌...\" << endl;\n\t}\n};\nvoid DoBussiness(Animal& animal){\n\tanimal.speak();\n}\nvoid test(){\n\tDog dog;\n\tDoBussiness(dog);\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class A{\npublic:\n\tvirtual void func1(){}\n\tvirtual void func2(){}\n};\n\n//B类为空，那么大小应该是1字节，实际情况是这样吗？\nclass B : public A{};\n\nvoid test(){\n\tcout << \"A size:\" << sizeof(A) << endl;\n\tcout << \"B size:\" << sizeof(B) << endl;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class People{\npublic:\n\tPeople(){\n\t\tcout << \"构造函数 People!\" << endl;\n\t}\n\tvirtual void showName() = 0;\n\tvirtual ~People(){\n\t\tcout << \"析构函数 People!\" << endl;\n\t}\n};\n\nclass Worker : public People{\npublic:\n\tWorker(){\n\t\tcout << \"构造函数 Worker!\" << endl;\n\t\tpName = new char[10];\n\t}\n\tvirtual void showName(){\n\t\tcout << \"打印子类的名字!\" << endl;\n\t}\n\t~Worker(){\n\t\tcout << \"析构函数 Worker!\" << endl;\n\t\tif (pName != NULL){\n\t\t\tdelete pName;\n\t\t}\n\t}\nprivate:\n\tchar* pName;\n};\n\nvoid test(){\n\n\tPeople* people = new Worker;\n\tpeople->~People();\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//非纯虚析构函数\nclass A{\npublic:\n\tvirtual ~A();\n};\n\nA::~A(){}\n\n//纯析构函数\nclass B{\npublic:\n\tvirtual ~B() = 0;\n};\n\nB::~B(){}\n\nvoid test(){\n\tA a; //A类不是抽象类，可以实例化对象\n\tB b; //B类是抽象类，不可以实例化对象\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class A{\npublic:\n\t//同一作用域下，func1函数重载\n\tvoid func1(){}\n\tvoid func1(int a){}\n\tvoid func1(int a,int b){}\n\tvoid func2(){}\n\tvirtual void func3(){}\n};\n\nclass B : public A{\npublic:\n\t//重定义基类的func2,隐藏了基类的func2方法\n\tvoid func2(){}\n\t//重写基类的func3函数，也可以覆盖基类func3\n\tvirtual void func3(){}\n};"
    }
  ],
  "58954472": [
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//交换int数据\nvoid SwapInt(int& a,int& b){\n\tint temp = a;\n\ta = b;\n\tb = temp;\n}\n\n//交换char数据\nvoid SwapChar(char& a,char& b){\n\tchar temp = a;\n\ta = b;\n\tb = temp;\n}\n//问题：如果我要交换double类型数据，那么还需要些一个double类型数据交换的函数\n//繁琐，写的函数越多，当交换逻辑发生变化的时候，所有的函数都需要修改，无形当中增加了代码的维护难度\n\n//如果能把类型作为参数传递进来就好了，传递int就是Int类型交换，传递char就是char类型交换\n//我们有一种技术，可以实现类型的参数化---函数模板\n\n\n//class 和 typename都是一样的，用哪个都可以\ntemplate<class T>\nvoid MySwap(T& a,T& b){\n\tT temp = a;\n\ta = b;\n\tb = temp;\n}\n\nvoid test01(){\n\t\n\tint a = 10;\n\tint b = 20;\n\tcout << \"a:\" << a << \" b:\" << b << endl;\n\t//1. 这里有个需要注意点，函数模板可以自动推导参数的类型\n\tMySwap(a,b);\n\tcout << \"a:\" << a << \" b:\" << b << endl;\n\n\tchar c1 = 'a';\n\tchar c2 = 'b';\n\tcout << \"c1:\" << c1 << \" c2:\" << c2 << endl;\n\t//2. 函数模板可以自动类型推导，那么也可以显式指定类型\n\tMySwap<char>(c1, c2);\n\tcout << \"c1:\" << c1 << \" c2:\" << c2 << endl;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//函数模板\ntemplate<class T>\nT MyPlus(T a, T b){\n\tT ret = a + b;\n\treturn ret;\n}\n\n//普通函数\nint MyPlus(int a,char b){\n\tint ret = a + b;\n\treturn ret;\n}\n\nvoid test02(){\n\n\tint a = 10;\n\tchar b = 'a';\n\n\t//调用函数模板，严格匹配类型\n\tMyPlus(a, a);\n\tMyPlus(b, b);\n\t//调用普通函数\n\tMyPlus(a, b);\n\t//调用普通函数  普通函数可以隐式类型转换\n\tMyPlus(b, a);\n\n\t//结论：\n\t//函数模板不允许自动类型转换，必须严格匹配类型\n\t//普通函数可以进行自动类型转换\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//函数模板\ntemplate<class T>\nT MyPlus(T a, T b){\n\tT ret = a + b;\n\treturn ret;\n}\n\n//普通函数\nint MyPlus(int a, int b){\n\tint ret = a + b;\n\treturn ret;\n}\n\nvoid test03(){\n\tint a = 10;\n\tint b = 20;\n\tchar c = 'a';\n\tchar d = 'b';\n\t//如果函数模板和普通函数都能匹配，c++编译器优先考虑普通函数\n\tcout << MyPlus(a, b) << endl;\n\t//如果我必须要调用函数模板,那么怎么办?\n\tcout << MyPlus<>(a, b) << endl;\n\t//此时普通函数也可以匹配，因为普通函数可以自动类型转换\n\t//但是此时函数模板能够有更好的匹配\n\t//如果函数模板可以产生一个更好的匹配，那么选择模板\n\tcout << MyPlus(c,d);\n}\n\n//函数模板重载\ntemplate<class T>\nT MyPlus(T a, T b, T c){\n\tT ret = a + b + c;\n\treturn ret;\n}\n\nvoid test04(){\n\n\tint a = 10;\n\tint b = 20;\n\tint c = 30;\n\tcout << MyPlus(a, b, c) << endl;\n\t//如果函数模板和普通函数都能匹配，c++编译器优先考虑普通函数\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Person\n{\npublic:\n\tPerson(string name, int age)\n\t{\n\t\tthis->mName = name;\n\t\tthis->mAge = age;\n\t}\n\tstring mName;\n\tint mAge;\n};\n\n//普通交换函数\ntemplate <class T>\nvoid mySwap(T &a,T &b)\n{\n\tT temp = a;\n\ta = b; \n\tb = temp;\n}\n//第三代具体化，显示具体化的原型和定意思以template<>开头，并通过名称来指出类型\n//具体化优先于常规模板\ntemplate<>void  mySwap<Person>(Person &p1, Person &p2)\n{\n\tstring nameTemp;\n\tint ageTemp;\n\n\tnameTemp = p1.mName;\n\tp1.mName = p2.mName;\n\tp2.mName = nameTemp;\n\n\tageTemp = p1.mAge;\n\tp1.mAge = p2.mAge;\n\tp2.mAge = ageTemp;\n\n}\n\nvoid test()\n{\n\tPerson P1(\"Tom\", 10);\n\tPerson P2(\"Jerry\", 20);\n\n\tcout << \"P1 Name = \" << P1.mName << \" P1 Age = \" << P1.mAge << endl;\n\tcout << \"P2 Name = \" << P2.mName << \" P2 Age = \" << P2.mAge << endl;\n\tmySwap(P1, P2);\n\tcout << \"P1 Name = \" << P1.mName << \" P1 Age = \" << P1.mAge << endl;\n\tcout << \"P2 Name = \" << P2.mName << \" P2 Age = \" << P2.mAge << endl;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "template<class NameType, class AgeType>\nclass Person\n{\npublic:\n\tPerson(NameType name, AgeType age)\n\t{\n\t\tthis->mName = name;\n\t\tthis->mAge = age;\n\t}\n\tvoid showPerson()\n\t{\n\t\tcout << \"name: \" << this->mName << \" age: \" << this->mAge << endl;\n\t}\npublic:\n\tNameType mName;\n\tAgeType mAge;\n};\n\nvoid test01()\n{\n\t//Person P1(\"德玛西亚\",18); // 类模板不能进行类型自动推导 \n\tPerson<string, int>P1(\"德玛西亚\", 18);\n\tP1.showPerson();\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//类模板\ntemplate<class NameType, class AgeType>\nclass Person{\npublic:\n\tPerson(NameType name, AgeType age){\n\t\tthis->mName = name;\n\t\tthis->mAge = age;\n\t}\n\tvoid PrintPerson(){\n\t\tcout << \"Name:\" << this->mName << \" Age:\" << this->mAge << endl;\n\t}\npublic:\n\tNameType mName;\n\tAgeType mAge;\n};\n\n//类模板做函数参数\nvoid DoBussiness(Person<string,int>& p){\n\tp.mAge += 20;\n\tp.mName += \"_vip\";\n\tp.PrintPerson();\n}\n\nint main(){\n\n\tPerson<string, int> p(\"John\", 30);\n\tDoBussiness(p);\n\n\tsystem(\"pause\");\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//类模板\ntemplate<class T>\nclass MyClass{\npublic:\n\tMyClass(T property){\n\t\tthis->mProperty = property;\n\t}\npublic:\n\tT mProperty;\n};\n\n//子类实例化的时候需要具体化的父类，子类需要知道父类的具体类型是什么样的\n//这样c++编译器才能知道给子类分配多少内存\n\n//普通派生类\nclass SubClass : public MyClass<int>{\npublic:\n\tSubClass(int b) : MyClass<int>(20){\n\t\tthis->mB = b;\n\t}\npublic:\n\tint mB;\n};"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//父类类模板\ntemplate<class T>\nclass Base\n{\n\tT m;\n};\ntemplate<class T >\nclass Child2 : public Base<double>  //继承类模板的时候，必须要确定基类的大小\n{\npublic:\n\tT mParam;\n};\n\nvoid test02()\n{\n\tChild2<int> d2;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "template<class NameType, class AgeType>\nclass Person\n{\npublic:\n\tPerson(NameType name, AgeType age)\n\t{\n\t\tthis->mName = name;\n\t\tthis->mAge = age;\n\t}\n\tvoid showPerson()\n\t{\n\t\tcout << \"name: \" << this->mName << \" age: \" << this->mAge << endl;\n\t}\npublic:\n\tNameType mName;\n\tAgeType mAge;\n};\n\nvoid test01()\n{\n\t//Person P1(\"德玛西亚\",18); // 类模板不能进行类型自动推导 \n\tPerson<string, int>P1(\"德玛西亚\", 18);\n\tP1.showPerson();\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "#define _CRT_SECURE_NO_WARNINGS\n#include<iostream>\n#include<string>\nusing namespace std;\n\ntemplate<class T1, class T2>\nclass Person{\npublic:\n\tPerson(T1 name, T2 age);\n\tvoid showPerson();\n\npublic:\n\tT1 mName;\n\tT2 mAge;\n};\n\n\n//类外实现\ntemplate<class T1, class T2>\nPerson<T1, T2>::Person(T1 name, T2 age){\n\tthis->mName = name;\n\tthis->mAge = age;\n}\n\n\ntemplate<class T1, class T2>\nvoid Person<T1, T2>::showPerson(){\n\tcout << \"Name:\" << this->mName << \" Age:\" << this->mAge << endl;\n}\n\nvoid test()\n{\n\tPerson<string, int> p(\"Obama\", 20);\n\tp.showPerson();\n}\n\nint main(){\n\n\ttest();\n\n\tsystem(\"pause\");\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "#define _CRT_SECURE_NO_WARNINGS\n#include<iostream>\nusing namespace std;\n#include <string>\n\ntemplate<class T1, class T2> class Person;\n//告诉编译器这个函数模板是存在\ntemplate<class T1, class T2> void PrintPerson2(Person<T1, T2>& p);\n\n//友元函数在类内实现\ntemplate<class T1, class T2>\nclass Person{\n\t//1. 友元函数在类内实现\n\tfriend void PrintPerson(Person<T1, T2>& p){\n\t\tcout << \"Name:\" << p.mName << \" Age:\" << p.mAge << endl;\n\t}\n\n\t//2.友元函数类外实现\n\t//告诉编译器这个函数模板是存在\n\tfriend void PrintPerson2<>(Person<T1, T2>& p);\n\n\t//3. 类模板碰到友元函数模板\n\ttemplate<class U1, class U2>\n\tfriend void PrintPerson(Person<U1, U2>& p);\n\npublic:\n\tPerson(T1 name, T2 age){\n\t\tthis->mName = name;\n\t\tthis->mAge = age;\n\t}\n\tvoid showPerson(){\n\t\tcout << \"Name:\" << this->mName << \" Age:\" << this->mAge << endl;\n\t}\nprivate:\n\tT1 mName;\n\tT2 mAge;\n};\n\nvoid test01()\n{\n\tPerson <string, int>p(\"Jerry\", 20);\n\tPrintPerson(p);\n}\n\n\n// 类模板碰到友元函数\n//友元函数类外实现  加上<>空参数列表，告诉编译去匹配函数模板\ntemplate<class T1 , class T2>\nvoid PrintPerson2(Person<T1, T2>& p)\n{\n\tcout << \"Name2:\" << p.mName << \" Age2:\" << p.mAge << endl;\n}\n\nvoid  test02()\n{\n\tPerson <string, int>p(\"Jerry\", 20);\n\tPrintPerson2(p);   //不写可以编译通过，写了之后，会找PrintPerson2的普通函数调用，因为写了普通函数PrintPerson2的声明\t\n}\n\nint main(){\n\n\t//test01();\n\ttest02();\n\tsystem(\"pause\");\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "#pragma once\ntemplate<class T>\nclass MyArray\n{\npublic:\n\texplicit MyArray(int capacity)\n\t{\n\t\tthis->m_Capacity = capacity;\n\t\tthis->m_Size = 0;\n\t\t// 如果T是对象，那么这个对象必须提供默认的构造函数\n\t\tpAddress = new T[this->m_Capacity];\n\t}\n\n\t//拷贝构造\n\tMyArray(const MyArray & arr)\n\t{\n\t\tthis->m_Capacity = arr.m_Capacity;\n\t\tthis->m_Size = arr.m_Size;\n\t\tthis->pAddress = new T[this->m_Capacity];\n\t\tfor (int i = 0; i < this->m_Size;i++)\n\t\t{\n\t\t\tthis->pAddress[i] = arr.pAddress[i];\n\t\t}\n\t}\n\n\t//重载[] 操作符  arr[0]\n\tT& operator [](int index)\n\t{\n\t\treturn this->pAddress[index]; \n\t}\n\t//尾插法\n\tvoid Push_back(const T & val)\n\t{\n\t\tif (this->m_Capacity == this->m_Size)\n\t\t{\n\t\t\treturn;\n\t\t}\n\t\tthis->pAddress[this->m_Size] = val;\n\t\tthis->m_Size++;\n\t}\n\tvoid Pop_back()\n\t{\n\t\tif (this->m_Size == 0)\n\t\t{\n\t\t\treturn;\n\t\t}\n\t\tthis->m_Size--;\n\t}\n\tint\tgetSize()\n\t{\n\t\treturn this->m_Size;\n\t}\n\t//析构\n\t~MyArray()\n\t{\n\t\tif (this->pAddress != NULL)\n\t\t{\n\t\t\tdelete[] this->pAddress;\n\t\t\tthis->pAddress = NULL;\n\t\t\tthis->m_Capacity = 0; \n\t\t\tthis->m_Size = 0;\n\t\t}\n\t}\n\nprivate:\n\tT * pAddress;  //指向一个堆空间，这个空间存储真正的数据\n\tint m_Capacity; //容量\n\tint m_Size;   // 大小\n};\n\n测试代码：\n\n\nclass Person{\npublic:\n\tPerson(){}\n\tPerson(string name, int age){\n\t\tthis->mName = name;\n\t\tthis->mAge = age;\n\t}\npublic:\n\tstring mName;\n\tint mAge;\n};\n\n\nvoid PrintMyArrayInt(MyArray<int>& arr){\n\tfor (int i = 0; i < arr.getSize(); i++){\n\t\tcout << arr[i] << \" \";\n\t}\n\tcout << endl;\n}\n\nvoid PrintMyPerson(MyArray<Person>& personArr)\n{\n\tfor (int i = 0; i < personArr.getSize(); i++){\n\t\tcout << \"姓名：\" << personArr[i].mName << \" 年龄： \" << personArr[i].mAge << endl;\n\t}\n\t\n}\n\t\n\tMyArray<int> myArrayInt(10);\n\tfor (int i = 0; i < 9; i++)\n\t{\n\t\tmyArrayInt.Push_back(i);\n\t}\n\tmyArrayInt.Push_back(100);\n\tPrintMyArrayInt(myArrayInt);\n\nMyArray<Person> myArrayPerson(10);\n\tPerson p1(\"德玛西亚\", 30);\n\tPerson p2(\"提莫\", 20);\n\tPerson p3(\"孙悟空\",18);\n\tPerson p4(\"赵信\", 15);\n\tPerson p5(\"赵云\", 24);\n\tmyArrayPerson.Push_back(p1);\n\tmyArrayPerson.Push_back(p2);\n\tmyArrayPerson.Push_back(p3);\n\tmyArrayPerson.Push_back(p4);\n\tmyArrayPerson.Push_back(p5);"
    }
  ],
  "58954473": [
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Animal{};\nclass Dog : public Animal{};\nclass Other{};\n\n//基础数据类型转换\nvoid test01(){\n\tchar a = 'a';\n\tdouble b = static_cast<double>(a);\n}\n\n//继承关系指针互相转换\nvoid test02(){\n\t//继承关系指针转换\n\tAnimal* animal01 = NULL;\n\tDog* dog01 = NULL;\n\t//子类指针转成父类指针,安全\n\tAnimal* animal02 = static_cast<Animal*>(dog01);\n\t//父类指针转成子类指针，不安全\n\tDog* dog02 = static_cast<Dog*>(animal01);\n}\n\n//继承关系引用相互转换\nvoid test03(){\n\n\tAnimal ani_ref;\n\tDog dog_ref;\n\t//继承关系指针转换\n\tAnimal& animal01 = ani_ref;\n\tDog& dog01 = dog_ref;\n\t//子类指针转成父类指针,安全\n\tAnimal& animal02 = static_cast<Animal&>(dog01);\n\t//父类指针转成子类指针，不安全\n\tDog& dog02 = static_cast<Dog&>(animal01);\n}\n\n//无继承关系指针转换\nvoid test04(){\n\t\n\tAnimal* animal01 = NULL;\n\tOther* other01 = NULL;\n\n\t//转换失败\n\t//Animal* animal02 = static_cast<Animal*>(other01);\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Animal {\npublic:\n\tvirtual void ShowName() = 0;\n};\nclass Dog : public Animal{\n\tvirtual void ShowName(){\n\t\tcout << \"I am a dog!\" << endl;\n\t}\n};\nclass Other {\npublic:\n\tvoid PrintSomething(){\n\t\tcout << \"我是其他类!\" << endl;\n\t}\n};\n\n//普通类型转换\nvoid test01(){\n\n\t//不支持基础数据类型\n\tint a = 10;\n\t//double a = dynamic_cast<double>(a);\n}\n\n//继承关系指针\nvoid test02(){\n\n\tAnimal* animal01 = NULL;\n\tDog* dog01 = new Dog;\n\n\t//子类指针转换成父类指针 可以\n\tAnimal* animal02 = dynamic_cast<Animal*>(dog01);\n\tanimal02->ShowName();\n\t//父类指针转换成子类指针 不可以\n\t//Dog* dog02 = dynamic_cast<Dog*>(animal01);\n}\n\n//继承关系引用\nvoid test03(){\n\n\tDog dog_ref;\n\tDog& dog01 = dog_ref;\n\n\t//子类引用转换成父类引用 可以\n\tAnimal& animal02 = dynamic_cast<Animal&>(dog01);\n\tanimal02.ShowName();\n}\n\n//无继承关系指针转换\nvoid test04(){\n\t\n\tAnimal* animal01 = NULL;\n\tOther* other = NULL;\n\n\t//不可以\n\t//Animal* animal02 = dynamic_cast<Animal*>(other);\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//常量指针转换成非常量指针\nvoid test01(){\n\t\n\tconst int* p = NULL;\n\tint* np = const_cast<int*>(p);\n\n\tint* pp = NULL;\n\tconst int* npp = const_cast<const int*>(pp);\n\n\tconst int a = 10;  //不能对非指针或非引用进行转换\n\t//int b = const_cast<int>(a); }\n\n//常量引用转换成非常量引用\nvoid test02(){\n\nint num = 10;\n\tint & refNum = num;\n\n\tconst int& refNum2 = const_cast<const int&>(refNum);\n\t\n}"
    }
  ],
  "58954474": [
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//如果判断返回值，那么返回值是错误码还是结果？\n//如果不判断返回值，那么b==0时候，程序结果已经不正确\n//A写的代码\nint A_MyDivide(int a,int b){\n\tif (b == 0){\n\t\treturn -1;\n\t}\n\n\treturn a / b;\n}\n\n//B写的代码\nint B_MyDivide(int a,int b){\n\n\tint ba = a + 100;\n\tint bb = b;\n\n\tint ret = A_MyDivide(ba, bb);  //由于B没有处理异常，导致B结果运算错误\n\n\treturn ret;\n}\n\n//C写的代码\nint C_MyDivide(){\n\n\tint a = 10;\n\tint b = 0;\n\n\tint ret = B_MyDivide(a, b); //更严重的是，由于B没有继续抛出异常，导致C的代码没有办法捕获异常\n\tif (ret == -1){\n\t\treturn -1;\n\t}\n\telse{\n\t\treturn ret;\n\t}\n}\n\n//所以,我们希望：\n//1.异常应该捕获，如果你捕获，可以，那么异常必须继续抛给上层函数,你不处理，不代表你的上层不处理\n//2.这个例子，异常没有捕获的结果就是运行结果错的一塌糊涂，结果未知，未知的结果程序没有必要执行下去"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "int A_MyDivide(int a, int b){\n\tif (b == 0){\n\t\tthrow 0;\n\t}\n\n\treturn a / b;\n}\n\n//B写的代码 B写代码比较粗心，忘记处理异常\nint B_MyDivide(int a, int b){\n\n\tint ba = a;\n\tint bb = b;\n\n\tint ret = A_MyDivide(ba, bb) + 100;  //由于B没有处理异常，导致B结果运算错误\n\n\treturn ret;\n}\n\n//C写的代码\nint C_MyDivide(){\n\n\tint a = 10;\n\tint b = 0;\n\n\tint ret = 0;\n\n//没有处理异常，程序直接中断执行\n#if 1 \n\tret = B_MyDivide(a, b);\n\n//处理异常\n#else \n\ttry{\n\t\tret = B_MyDivide(a, b); //更严重的是，由于B没有继续抛出异常，导致C的代码没有办法捕获异常\n\t}\n\tcatch (int e){\n\t\tcout << \"C_MyDivide Call B_MyDivide 除数为:\" << e << endl;\n\t}\n#endif\n\t\n\treturn ret;\n}\n\nint main(){\n\n\tC_MyDivide();\n\n\tsystem(\"pause\");\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "void TestFunction(){\n\t\n\tcout << \"开始抛出异常...\" << endl;\n\t//throw 10; //抛出int类型异常\n\t//throw 'a'; //抛出char类型异常\n\t//throw \"abcd\"; //抛出char*类型异常\n\tstring ex = \"string exception!\";\n\tthrow ex;\n\n}\n\nint main(){\n\n\ttry{\n\t\tTestFunction();\n\t}\n\tcatch (int){\n\t\tcout << \"抛出Int类型异常!\" << endl;\n\t}\n\tcatch (char){\n\t\tcout << \"抛出Char类型异常!\" << endl;\n\t}\n\tcatch (char*){\n\t\tcout << \"抛出Char*类型异常!\" << endl;\n\t}\n\tcatch (string){\n\t\tcout << \"抛出string类型异常!\" << endl;\n\t}\n\t//捕获所有异常\n\tcatch (...){\n\t\tcout << \"抛出其他类型异常!\" << endl;\n\t}\n\n\n\tsystem(\"pause\");\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Person{\npublic:\n\tPerson(string name){\n\t\tmName = name;\n\t\tcout << mName << \"对象被创建!\" << endl;\n\t}\n\t~Person(){\n\t\tcout << mName << \"对象被析构!\" << endl;\n\t}\npublic:\n\tstring mName;\n};\n\nvoid TestFunction(){\n\t\n\tPerson p1(\"aaa\");\n\tPerson p2(\"bbb\");\n\tPerson p3(\"ccc\");\n\n\t//抛出异常\n\tthrow 10;\n}\n\nint main(){\n\n\ttry{\n\t\tTestFunction();\n\t}\n\tcatch (...){\n\t\tcout << \"异常被捕获!\" << endl;\n\t}\n\n\tsystem(\"pause\");\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//可抛出所有类型异常\nvoid TestFunction01(){\n\tthrow 10;\n}\n\n//只能抛出int char char*类型异常\nvoid TestFunction02() throw(int,char,char*){\n\tstring exception = \"error!\";\n\tthrow exception;\n}\n\n//不能抛出任何类型异常\nvoid TestFunction03() throw(){\n\tthrow 10;\n}\n\nint main(){\n\n\ttry{\n\t\t//TestFunction01();\n\t\t//TestFunction02();\n\t\t//TestFunction03();\n\t}\n\tcatch (...){\n\t\tcout << \"捕获异常!\" << endl;\n\t}\n\t\n\tsystem(\"pause\");\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class MyException\n{\npublic:\n\tMyException(){\n\t\tcout << \"异常变量构造\" << endl;\n\t};\n\tMyException(const MyException & e)\n\t{\n\t\tcout << \"拷贝构造\" << endl;\n\t}\n\t~MyException()\n\t{\n\t\tcout << \"异常变量析构\" << endl;\n\t}\n};\nvoid DoWork()\n{\n\tthrow new MyException(); //test1 2都用 throw MyExecption();\n}\n\nvoid test01()\n{\n\ttry\n\t{\n\t\tDoWork();\n\t}\n\tcatch (MyException e)\n\t{\n\t\tcout << \"捕获 异常\" << endl;\n\t}\n}\nvoid test02()\n{\n\ttry\n\t{\n\t\tDoWork();\n\t}\n\tcatch (MyException &e)\n\t{\n\t\tcout << \"捕获 异常\" << endl;\n\t}\n}\n\nvoid test03()\n{\n\ttry\n\t{\n\t\tDoWork();\n\t}\n\tcatch (MyException *e)\n\t{\n\t\tcout << \"捕获 异常\" << endl;\n\t\tdelete e;\n\t}\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//异常基类\nclass BaseException{\npublic:\n\tvirtual void printError(){};\n};\n\n//空指针异常\nclass NullPointerException : public BaseException{\npublic:\n\tvirtual void printError(){\n\t\tcout << \"空指针异常!\" << endl;\n\t}\n};\n//越界异常\nclass OutOfRangeException : public BaseException{\npublic:\n\tvirtual void printError(){\n\t\tcout << \"越界异常!\" << endl;\n\t}\n};\n\nvoid doWork(){\n\n\tthrow NullPointerException();\n}\n\nvoid test()\n{\n\ttry{\n\t\tdoWork();\n\t}\n\tcatch (BaseException& ex){\n\t\tex.printError();\n\t}\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "#include<stdexcept>\nclass Person{\npublic:\n\tPerson(int age){\n\t\tif (age < 0 || age > 150){\n\t\t\tthrow out_of_range(\"年龄应该在0-150岁之间!\");\n\t\t}\n\t}\npublic:\n\tint mAge;\n};\n\nint main(){\n\n\ttry{\n\t\tPerson p(151);\n\t}\n\tcatch (out_of_range& ex){\n\t\tcout << ex.what() << endl;\n\t}\n\t\n\tsystem(\"pause\");\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//自定义异常类\nclass MyOutOfRange:public exception\n{\npublic:\n\tMyOutOfRange(const string  errorInfo)\n\t{\n\t\tthis->m_Error = errorInfo;\n\t}\n\n\tMyOutOfRange(const char * errorInfo)\n\t{\n\t\tthis->m_Error = string( errorInfo);\n\t}\n\n\tvirtual  ~MyOutOfRange()\n\t{\n\t\n\t}\n\tvirtual const char *  what() const\n\t{\n\t\treturn this->m_Error.c_str() ;\n\t}\n\n\tstring m_Error;\n\n};\n\nclass Person\n{\npublic:\n\tPerson(int age)\n\t{\n\t\tif (age <= 0 || age > 150)\n\t\t{\n\t\t\t//抛出异常 越界\n\t\t\t//cout << \"越界\" << endl;\n\t\t\t//throw  out_of_range(\"年龄必须在0~150之间\");\n\n\t\t\t//throw length_error(\"长度异常\");\n\t\t\tthrow MyOutOfRange((\"我的异常 年龄必须在0~150之间\"));\n\t\t}\n\t\telse\n\t\t{\n\t\t\tthis->m_Age = age;\n\t\t}\n\t\t\n\t}\n\n\tint m_Age;\n};\n\n\nvoid test01()\n{\n\ttry\n\t{\n\t\tPerson p(151);\n\t}\n\tcatch ( out_of_range & e )\n\t{\n\t\tcout << e.what() << endl;\n\t}\n\tcatch (length_error & e)\n\t{\n\t\tcout << e.what() << endl;\n\t}\n\tcatch (MyOutOfRange e)\n\t{\n\t\tcout << e.what() << endl;\n\t}\n}"
    }
  ],
  "58954476": [
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//cin.get\nvoid test01(){\n#if 0\n\tchar ch = cin.get();\n\tcout << ch << endl;\n\n\tcin.get(ch);\n\tcout << ch << endl;\n\n\n\t//链式编程\n\tchar char1, char2, char3, char4;\n\tcin.get(char1).get(char2).get(char3).get(char4);\n\n\tcout << char1 << \" \" << char2 << \"\" << char3 <<  \" \" << char4 << \" \";\n#endif\n\n\tchar buf[1024] = { 0 };\n\t//cin.get(buf.1024);\n\tcin.getline(buf,1024);\n\tcout << buf;\n}\n\n//cin.ignore\nvoid test02(){\n\n\tchar buf[1024] = { 0 };\n\tcin.ignore(2); //忽略缓冲区当前字符\n\tcin.get(buf,1024);\n\tcout << buf << endl;\n}\n\n//cin.putback 将数据放回缓冲区\nvoid test03(){\n\n\t//从缓冲区取走一个字符\n\tchar ch = cin.get();\n\tcout << \"从缓冲区取走的字符:\" << ch << endl;\n\t//将数据再放回缓冲区\n\tcin.putback(ch);\n\tchar buf[1024] = { 0 };\n\tcin.get(buf,1024);\n\tcout << buf << endl;\n\n}\n\n//cin.peek 偷窥\nvoid test04(){\n\t\n\t//偷窥下缓冲区的数据\n\tchar ch = cin.peek();\n\tcout << \"偷窥缓冲区数据:\" << ch << endl;\n\tchar buf[1024] = { 0 };\n\tcin.get(buf, 1024);\n\tcout << buf << endl;\n}\n\n//练习  作业 使用cin.get和putback完成类似功能\nvoid test05(){\n\t\n\tcout << \"请输入一个数字或者字符串:\" << endl;\n\tchar ch = cin.peek();\n\tif(ch >= '0' && ch <= '9'){\n\t\tint number;\n\t\tcin >> number;\n\t\tcout << \"数字:\" << number << endl;\n\t}\n\telse{\n\t\tchar buf[64] = { 0 };\n\t\tcin.getline(buf, 64);\n\t\tcout << \"字符串:\" <<  buf << endl;\n\t}\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//cout.flush 刷新缓冲区，linux下有效\nvoid test01(){\t\n\tcout << \"hello world\";\n\t//刷新缓冲区\n\tcout.flush(); \n}\n\n//cout.put 输出一个字符\nvoid test02(){\n\t\n\tcout.put('a');\n\t//链式编程\n\tcout.put('h').put('e').put('l');\n}\n\n//cout.write 输出字符串 buf,输出多少个\nvoid test03(){\n\t\n\t//char* str = \"hello world!\";\n\t//cout.write(str, strlen(str));\n\tchar* str = \"*************\";\n\tfor (int i = 1; i <= strlen(str); i ++){\n\t\tcout.write(str, i);\n\t\tcout << endl;\n\t}\n\n\tfor (int i = strlen(str); i > 0; i --){\n\t\tcout.write(str, i);\n\t\tcout << endl;\n\t}\n\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//通过流成员函数\nvoid test01(){\n\t\n\tint number = 99;\n\tcout.width(20);\n\tcout.fill('*');\n\tcout.setf(ios::left);\n\tcout.unsetf(ios::dec); //卸载十进制\n\tcout.setf(ios::hex);\n\tcout.setf(ios::showbase);\n\tcout.unsetf(ios::hex);\n\tcout.setf(ios::oct);\n\tcout << number << endl;\n\n}\n\n//使用控制符\nvoid test02(){\n\n\tint number = 99;\n\tcout << setw(20)\n\t\t<< setfill('~')\n\t\t<< setiosflags(ios::showbase)\n\t\t<< setiosflags(ios::left)\n\t\t<< hex\n\t\t<< number\n\t\t<< endl;\n\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "int main(){\n\n\tchar* sourceFileName = \"./source.txt\";\n\tchar* targetFileName = \"./target.txt\";\n\t//创建文件输入流对象\n\tifstream ism(sourceFileName, ios::in);\n\t//创建文件输出流对象\n\tofstream osm(targetFileName,ios::out);\n\n\tif (!ism){\n\t\tcout << \"文件打开失败!\" << endl;\n\t}\n\n\twhile (!ism.eof()){\n\t\tchar buf[1024] = { 0 };\n\t\tism.getline(buf,1024);\n\t\tcout << buf << endl;\n\t\tosm << buf << endl;\n\t}\n\n\t//关闭文件流对象\n\tism.close();\n\tosm.close();\n\n\tsystem(\"pause\");\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class Person{\npublic:\n\tPerson(char* name,int age){\n\t\tstrcpy(this->mName, name);\n\t\tthis->mAge = age;\n\t}\npublic:\n\tchar mName[64];\n\tint mAge;\n};\n\nint main(){\n\n\tchar* fileName = \"person.txt\";\n\t//二进制模式读写文件\n\t//创建文件对象输出流\n\tofstream osm(fileName, ios::out | ios::binary);\n\n\tPerson p1(\"John\",33);\n\tPerson p2(\"Edward\", 34);\n\n\t//Person对象写入文件\n\tosm.write((const char*)&p1,sizeof(Person));\n\tosm.write((const char*)&p2, sizeof(Person));\n\n\t//关闭文件输出流\n\tosm.close();\n\n\t//从文件中读取对象数组\n\tifstream ism(fileName, ios::in | ios::binary);\n\tif (!ism){\n\t\tcout << \"打开失败!\" << endl;\n\t}\n\t\n\tPerson p3;\n\tPerson p4;\n\n\tism.read((char*)&p3, sizeof(Person));\n\tism.read((char*)&p4, sizeof(Person));\n\n\tcout << \"Name:\" << p3.mName << \" Age:\" << p3.mAge << endl;\n\tcout << \"Age:\" << p4.mName << \" Age:\" << p4.mAge << endl;\n\n\t//关闭文件输入流\n\tism.close();\n\n\tsystem(\"pause\");\n\treturn EXIT_SUCCESS;\n}"
    }
  ],
  "58954485": [],
  "58954486": [],
  "58954487": [
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "#define _CRT_SECURE_NO_WARNINGS\n#include<iostream>\n#include<vector>\n#include<algorithm>\nusing namespace std;\n\n//STL 中的容器 算法 迭代器\nvoid test01(){\n\tvector<int> v; //STL 中的标准容器之一 ：动态数组\n\tv.push_back(1); //vector 容器提供的插入数据的方法\n\tv.push_back(5);\n\tv.push_back(3);\n\tv.push_back(7);\n\t//迭代器\n\tvector<int>::iterator pStart = v.begin(); //vector 容器提供了 begin()方法 返回指向第一个元素的迭代器\n\tvector<int>::iterator pEnd = v.end(); //vector 容器提供了 end()方法 返回指向最后一个元素下一个位置的迭代器\n\t//通过迭代器遍历\n\twhile (pStart != pEnd){\n\t\tcout << *pStart << \" \";\n\t\tpStart++;\n\t}\n\tcout << endl;\n}\n//STL 容器不单单可以存储基础数据类型，也可以存储类对象\nclass Teacher\n{\npublic:\n\tTeacher(int age) :age(age){};\n\t~Teacher(){};\npublic:\n\tint age;\n};\nvoid test02(){\n\tvector<Teacher> v; //存储 Teacher 类型数据的容器\n\tTeacher t1(10), t2(20), t3(30);\n\tv.push_back(t1);\n\tv.push_back(t2);\n\tv.push_back(t3);\n\tvector<Teacher>::iterator pStart = v.begin();\n\tvector<Teacher>::iterator pEnd = v.end();\n\t//通过迭代器遍历\n\twhile (pStart != pEnd){\n\t\tcout << pStart->age << \" \";\n\t\tpStart++;\n\t}\n\tcout << endl;\n}\n//存储 Teacher 类型指针\nvoid test03(){\n\tvector<Teacher*> v; //存储 Teacher 类型指针\n\tTeacher* t1 = new Teacher(10);\n\tTeacher* t2 = new Teacher(20);\n\tTeacher* t3 = new Teacher(30);\n\tv.push_back(t1);\n\tv.push_back(t2);\n\tv.push_back(t3);\n\t//拿到容器迭代器\n\tvector<Teacher*>::iterator pStart = v.begin();\n\tvector<Teacher*>::iterator pEnd = v.end();\n\t//通过迭代器遍历\n\twhile (pStart != pEnd){\n\t\tcout << (*pStart)->age << \" \";\n\t\tpStart++;\n\t}\n\tcout << endl;\n}\n//容器嵌套容器 难点(不理解，可以跳过)\nvoid test04()\n{\n\tvector< vector<int> > v;\n\tvector<int>v1;\n\tvector<int>v2;\n\tvector<int>v3;\n\n\tfor (int i = 0; i < 5;i++)\n\t{\n\t\tv1.push_back(i);\n\t\tv2.push_back(i * 10);\n\t\tv3.push_back(i * 100);\n\t}\n\tv.push_back(v1);\n\tv.push_back(v2);\n\tv.push_back(v3);\n\n\tfor (vector< vector<int> >::iterator it = v.begin(); it != v.end();it++)\n\t{\n\t\tfor (vector<int>::iterator subIt = (*it).begin(); subIt != (*it).end(); subIt ++)\n\t\t{\n\t\t\tcout << *subIt << \" \";\n\t\t}\n\t\tcout << endl;\n\t}\n} \nint main(){\n\t//test01();\n\t//test02();\n\t//test03();\n\ttest04();\n\tsystem(\"pause\");\n\treturn EXIT_SUCCESS;\n}"
    }
  ],
  "58954488": [
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "\tstring s = \"abcdefg\";\n\tchar& a = s[2];\n\tchar& b = s[3];\n\n\ta = '1';\n\tb = '2';\n\n\tcout << s << endl;\n\tcout << (int*)s.c_str() << endl;\n\n\ts = \"pppppppppppppppppppppppp\";\n\n\t//a = '1';\n\t//b = '2';\n\n\tcout << s << endl;\n\tcout << (int*)s.c_str() << endl;"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "#define _CRT_SECURE_NO_WARNINGS\n#include<iostream>\n#include<vector>\nusing namespace std;\n\nint main(){\n\n\tvector<int> v;\n\tfor (int i = 0; i < 10;i ++){\n\t\tv.push_back(i);\n\t\tcout << v.capacity() << endl;  // v.capacity()容器的容量\n\t}\n\n\n\tsystem(\"pause\");\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "#define _CRT_SECURE_NO_WARNINGS\n#include<iostream>\n#include<vector>\nusing namespace std;\n\nint main(){\n\n\tvector<int> v;\n\tfor (int i = 0; i < 100000;i ++){\n\t\tv.push_back(i);\n\t}\n\n\tcout << \"capacity:\" << v.capacity() << endl;\n\tcout << \"size:\" << v.size() << endl;\n\n\t//此时 通过resize改变容器大小\n\tv.resize(10);\n\n\tcout << \"capacity:\" << v.capacity() << endl;\n\tcout << \"size:\" << v.size() << endl;\n\n\t//容量没有改变\n\tvector<int>(v).swap(v);\n\n\tcout << \"capacity:\" << v.capacity() << endl;\n\tcout << \"size:\" << v.size() << endl;\n\n\n\tsystem(\"pause\");\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "#define _CRT_SECURE_NO_WARNINGS\n#include<iostream>\n#include<vector>\nusing namespace std;\n\nint main(){\n\n\tvector<int> v;\n\n\t//预先开辟空间\n\tv.reserve(100000);\n\n\tint* pStart = NULL;\n\tint count = 0;\n\tfor (int i = 0; i < 100000;i ++){\n\t\tv.push_back(i);\n\t\tif (pStart != &v[0]){\n\t\t\tpStart = &v[0];\n\t\t\tcount++;\n\t\t}\n\t}\n\n\tcout << \"count:\" << count << endl;\n\n\tsystem(\"pause\");\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "#define _CRT_SECURE_NO_WARNINGS\n#include<iostream>\n#include<list>\nusing namespace std;\n\nint main(){\n\n\tlist<int> myList;\n\tfor (int i = 0; i < 10; i ++){\n\t\tmyList.push_back(i);\n\t}\n\n\tlist<int>::_Nodeptr node =  myList._Myhead->_Next;\n\n\tfor (int i = 0; i < myList._Mysize * 2;i++){\n\t\tcout << \"Node:\" << node->_Myval << endl;\n\t\tnode = node->_Next;\n\t\tif (node == myList._Myhead){\n\t\t\tnode = node->_Next;\n\t\t}\n\t}\n\n\tsystem(\"pause\");\n\treturn EXIT_SUCCESS;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//插入操作返回值\nvoid test01(){\n\n\tset<int> s;\n\tpair<set<int>::iterator,bool> ret = s.insert(10);\n\tif (ret.second){\n\t\tcout << \"插入成功:\" << *ret.first << endl;\n\t}\n\telse{\n\t\tcout << \"插入失败:\" << *ret.first << endl;\n\t}\n\t\n\tret = s.insert(10);\n\tif(ret.second){\n\t\tcout << \"插入成功:\" << *ret.first << endl;\n\t}\n\telse{\n\t\tcout << \"插入失败:\" << *ret.first << endl;\n\t}\n\n}\n\nstruct MyCompare02{\n\tbool operator()(int v1,int v2){\n\t\treturn v1 > v2;\n\t}\n};\n\n//set从大到小\nvoid test02(){\n\n\tsrand((unsigned int)time(NULL));\n\t//我们发现set容器的第二个模板参数可以设置排序规则，默认规则是less<_Kty>\n\tset<int, MyCompare02> s;\n\tfor (int i = 0; i < 10;i++){\n\t\ts.insert(rand() % 100);\n\t}\n\t\n\tfor (set<int, MyCompare02>::iterator it = s.begin(); it != s.end(); it ++){\n\t\tcout << *it << \" \";\n\t}\n\tcout << endl;\n}\n\n//set容器中存放对象\nclass Person{\npublic:\n\tPerson(string name,int age){\n\t\tthis->mName = name;\n\t\tthis->mAge = age;\n\t}\npublic:\n\tstring mName;\n\tint mAge;\n};\n\n\nstruct MyCompare03{\n\tbool operator()(const Person& p1,const Person& p2){\n\t\treturn p1.mAge > p2.mAge;\n\t}\n};\n\nvoid test03(){\n\n\tset<Person, MyCompare03> s;\n\n\tPerson p1(\"aaa\", 20);\n\tPerson p2(\"bbb\", 30);\n\tPerson p3(\"ccc\", 40);\n\tPerson p4(\"ddd\", 50);\n\n\ts.insert(p1);\n\ts.insert(p2);\n\ts.insert(p3);\n\ts.insert(p4);\n\n\tfor (set<Person, MyCompare03>::iterator it = s.begin(); it != s.end(); it++){\n\t\tcout << \"Name:\" << it->mName << \" Age:\" << it->mAge << endl;\n\t}\n\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "#define _CRT_SECURE_NO_WARNINGS\n\n#include<iostream>\n#include<map>\n#include<string>\n#include<vector>\nusing namespace std;\n\n//multimap 案例\n//公司今天招聘了 5 个员工，5 名员工进入公司之后，需要指派员工在那个部门工作\n//人员信息有: 姓名 年龄 电话 工资等组成\n//通过 Multimap 进行信息的插入 保存 显示\n//分部门显示员工信息 显示全部员工信息\n\n\n#define SALE_DEPATMENT 1 //销售部门\n#define DEVELOP_DEPATMENT 2 //研发部门\n#define FINACIAL_DEPATMENT 3 //财务部门\n#define ALL_DEPATMENT 4 //所有部门\n\n//员工类\nclass person{\npublic:\n\tstring name; //员工姓名\n\tint age; //员工年龄\n\tdouble salary; //员工工资\n\tstring tele; //员工电话\n};\n\n//创建5个员工\nvoid CreatePerson(vector<person>& vlist){\n\n\tstring seed = \"ABCDE\";\n\tfor (int i = 0; i < 5; i++){\n\t\tperson p;\n\t\tp.name = \"员工\";\n\t\tp.name += seed[i];\n\t\tp.age = rand() % 30 + 20;\n\t\tp.salary = rand() % 20000 + 10000;\n\t\tp.tele = \"010-8888888\";\n\t\tvlist.push_back(p);\n\t}\n\n}\n\n//5名员工分配到不同的部门\nvoid PersonByGroup(vector<person>& vlist, multimap<int, person>& plist){\n\n\n\tint operate = -1; //用户的操作\n\n\tfor (vector<person>::iterator it = vlist.begin(); it != vlist.end(); it++){\n\n\t\tcout << \"当前员工信息:\" << endl;\n\t\tcout << \"姓名：\" << it->name << \" 年龄:\" << it->age << \" 工资:\" << it->salary << \" 电话：\" << it->tele << endl;\n\t\tcout << \"请对该员工进行部门分配(1 销售部门, 2 研发部门, 3 财务部门):\" << endl;\n\t\tscanf(\"%d\", &operate);\n\n\t\twhile (true){\n\n\t\t\tif (operate == SALE_DEPATMENT){  //将该员工加入到销售部门\n\t\t\t\tplist.insert(make_pair(SALE_DEPATMENT, *it));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (operate == DEVELOP_DEPATMENT){\n\t\t\t\tplist.insert(make_pair(DEVELOP_DEPATMENT, *it));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (operate == FINACIAL_DEPATMENT){\n\t\t\t\tplist.insert(make_pair(FINACIAL_DEPATMENT, *it));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tcout << \"您的输入有误，请重新输入(1 销售部门, 2 研发部门, 3 财务部门):\" << endl;\n\t\t\t\tscanf(\"%d\", &operate);\n\t\t\t}\n\n\t\t}\n\n\t}\n\tcout << \"员工部门分配完毕!\" << endl;\n\tcout << \"***********************************************************\" << endl;\n\n}\n\n//打印员工信息\nvoid printList(multimap<int, person>& plist, int myoperate){\n\n\tif (myoperate == ALL_DEPATMENT){\n\t\tfor (multimap<int, person>::iterator it = plist.begin(); it != plist.end(); it++){\n\t\t\tcout << \"姓名：\" << it->second.name << \" 年龄:\" << it->second.age << \" 工资:\" << it->second.salary << \" 电话：\" << it->second.tele << endl;\n\t\t}\n\t\treturn;\n\t}\n\n\tmultimap<int, person>::iterator it = plist.find(myoperate);\n\tint depatCount = plist.count(myoperate);\n\tint num = 0;\n\tif (it != plist.end()){\n\t\twhile (it != plist.end() && num < depatCount){\n\t\t\tcout << \"姓名：\" << it->second.name << \" 年龄:\" << it->second.age << \" 工资:\" << it->second.salary << \" 电话：\" << it->second.tele << endl;\n\t\t\tit++;\n\t\t\tnum++;\n\t\t}\n\t}\n}\n\n//根据用户操作显示不同部门的人员列表\nvoid ShowPersonList(multimap<int, person>& plist, int myoperate){\n\n\tswitch (myoperate)\n\t{\n\tcase SALE_DEPATMENT:\n\t\tprintList(plist, SALE_DEPATMENT);\n\t\tbreak;\n\tcase DEVELOP_DEPATMENT:\n\t\tprintList(plist, DEVELOP_DEPATMENT);\n\t\tbreak;\n\tcase FINACIAL_DEPATMENT:\n\t\tprintList(plist, FINACIAL_DEPATMENT);\n\t\tbreak;\n\tcase ALL_DEPATMENT:\n\t\tprintList(plist, ALL_DEPATMENT);\n\t\tbreak;\n\t}\n}\n\n//用户操作菜单\nvoid PersonMenue(multimap<int, person>& plist){\n\n\tint flag = -1;\n\tint isexit = 0;\n\twhile (true){\n\t\tcout << \"请输入您的操作((1 销售部门, 2 研发部门, 3 财务部门, 4 所有部门, 0退出)：\" << endl;\n\t\tscanf(\"%d\", &flag);\n\n\t\tswitch (flag)\n\t\t{\n\t\tcase SALE_DEPATMENT:\n\t\t\tShowPersonList(plist, SALE_DEPATMENT);\n\t\t\tbreak;\n\t\tcase DEVELOP_DEPATMENT:\n\t\t\tShowPersonList(plist, DEVELOP_DEPATMENT);\n\t\t\tbreak;\n\t\tcase FINACIAL_DEPATMENT:\n\t\t\tShowPersonList(plist, FINACIAL_DEPATMENT);\n\t\t\tbreak;\n\t\tcase ALL_DEPATMENT:\n\t\t\tShowPersonList(plist, ALL_DEPATMENT);\n\t\t\tbreak;\n\t\tcase 0:\n\t\t\tisexit = 1;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tcout << \"您的输入有误，请重新输入!\" << endl;\n\t\t\tbreak;\n\t\t}\n\n\t\tif (isexit == 1){\n\t\t\tbreak;\n\t\t}\n\t}\n\n}\n\nint main(){\n\n\tvector<person>  vlist; //创建的5个员工 未分组\n\tmultimap<int, person> plist; //保存分组后员工信息\n\n\t//创建5个员工\n\tCreatePerson(vlist);\n\t//5名员工分配到不同的部门\n\tPersonByGroup(vlist, plist);\n\t//根据用户输入显示不同部门员工信息列表 或者 显示全部员工的信息列表\n\tPersonMenue(plist);\n\n\tsystem(\"pause\");\n\treturn EXIT_SUCCESS;\n}"
    }
  ],
  "58954498": [
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//函数对象是重载了函数调用符号的类\nclass MyPrint\n{\npublic:\n\tMyPrint()\n\t{\n\t\tm_Num = 0;\n\t}\n\tint m_Num;\n\npublic:\n\tvoid operator() (int num)\n\t{\n\t\tcout << num << endl;\n\t\tm_Num++;\n\t}\n};\n\n//函数对象\n//重载了()操作符的类实例化的对象，可以像普通函数那样调用,可以有参数 ，可以有返回值\nvoid test01()\n{\n\tMyPrint myPrint;\n\tmyPrint(20);\n\n}\n// 函数对象超出了普通函数的概念，可以保存函数的调用状态\nvoid test02()\n{\n\tMyPrint myPrint;\n\tmyPrint(20);\n\tmyPrint(20);\n\tmyPrint(20);\n\tcout << myPrint.m_Num << endl;\n}\n\nvoid doBusiness(MyPrint print,int num)\n{\n\tprint(num);\n}\n\n//函数对象作为参数\nvoid test03()\n{\n\t//参数1：匿名函数对象\n\tdoBusiness(MyPrint(),30);\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class GreaterThenFive\n{\npublic:\n\tbool operator()(int num)\n\t{\n\t\treturn num > 5;\n\t}\n\n};\n//一元谓词\nvoid test01()\n{\n\tvector<int> v;\n\tfor (int i = 0; i < 10;i ++)\n\t{\n\t\tv.push_back(i);\n\t}\n\t\n\t vector<int>::iterator it =  find_if(v.begin(), v.end(), GreaterThenFive());\n\t if (it == v.end())\n\t {\n\t\t cout << \"没有找到\" << endl;\n\t }\n\t else\n\t {\n\t\t cout << \"找到了: \" << *it << endl;\n\t }\n}\n\n//二元谓词\nclass MyCompare\n{\npublic:\n\tbool operator()(int num1, int num2)\n\t{\n\t\treturn num1 > num2;\n\t}\n};\n\nvoid test02()\n{\n\tvector<int> v;\n\tv.push_back(10);\n\tv.push_back(40);\n\tv.push_back(20);\n\tv.push_back(90);\n\tv.push_back(60);\n\n\t//默认从小到大\n\tsort(v.begin(), v.end());\n\tfor (vector<int>::iterator it = v.begin(); it != v.end();it++)\n\t{\n\t\tcout << *it << \" \";\n\t}\n\tcout << endl;\n\tcout << \"----------------------------\" << endl;\n\t//使用函数对象改变算法策略，排序从大到小\n\tsort(v.begin(), v.end(),MyCompare());\n\tfor (vector<int>::iterator it = v.begin(); it != v.end(); it++)\n\t{\n\t\tcout << *it << \" \";\n\t}\n\tcout << endl;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//取反仿函数\nvoid test01()\n{\n\tnegate<int> n;\n\tcout << n(50) << endl;\n}\n\n//加法仿函数\nvoid test02()\n{\n\tplus<int> p;\n\tcout << p(10, 20) << endl;\n}\n\n//大于仿函数\nvoid test03()\n{\n\tvector<int> v;\n\tsrand((unsigned int)time(NULL));\n\tfor (int i = 0; i < 10; i++){\n\t\tv.push_back(rand() % 100);\n\t}\n\n\tfor (vector<int>::iterator it = v.begin(); it != v.end(); it++){\n\t\tcout << *it << \" \";\n\t}\n\tcout << endl;\n\tsort(v.begin(), v.end(), greater<int>());\n\n\tfor (vector<int>::iterator it = v.begin(); it != v.end(); it++){\n\t\tcout << *it << \" \";\n\t}\n\tcout << endl;\n\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//函数适配器bind1st bind2nd\n//现在我有这个需求 在遍历容器的时候，我希望将容器中的值全部加上100之后显示出来，怎么做？\n//我们直接给函数对象绑定参数 编译阶段就会报错\n//for_each(v.begin(), v.end(), bind2nd(myprint(),100));\n//如果我们想使用绑定适配器,需要我们自己的函数对象继承binary_function 或者 unary_function\n//根据我们函数对象是一元函数对象 还是二元函数对象\nclass MyPrint :public binary_function<int,int,void>\n{\npublic:\n\tvoid operator()(int v1,int v2) const\n\t{\n\t\tcout << \"v1 = : \" << v1 << \" v2 = :\" <<v2  << \" v1+v2 = :\" << (v1 + v2) << endl;\t\n\t}\n};\n//1、函数适配器\nvoid test01()\n{\n\tvector<int>v;\n\tfor (int i = 0; i < 10; i++)\n\t{\n\t\tv.push_back(i);\n\t}\n\tcout << \"请输入起始值：\" << endl;\n\tint x;\n\tcin >> x;\n\n\tfor_each(v.begin(), v.end(), bind1st(MyPrint(), x));\n\t//for_each(v.begin(), v.end(), bind2nd( MyPrint(),x ));\n}\n//总结：  bind1st和bind2nd区别?\n//bind1st ： 将参数绑定为函数对象的第一个参数\n//bind2nd ： 将参数绑定为函数对象的第二个参数\n//bind1st bind2nd将二元函数对象转为一元函数对象\n\n\nclass GreaterThenFive:public unary_function<int,bool>\n{\npublic:\n\tbool operator ()(int v) const\n\t{\n\t\treturn v > 5;\n\t}\n};\n\n//2、取反适配器\nvoid test02()\n{\n\tvector <int> v;\n\tfor (int i = 0; i < 10;i++)\n\t{\n\t\tv.push_back(i);\n\t}\n\t\n// \tvector<int>::iterator it =  find_if(v.begin(), v.end(), GreaterThenFive()); //返回第一个大于5的迭代器\n//\tvector<int>::iterator it = find_if(v.begin(), v.end(),  not1(GreaterThenFive())); //返回第一个小于5迭代器\n\t//自定义输入\n\tvector<int>::iterator it = find_if(v.begin(), v.end(), not1 ( bind2nd(greater<int>(),5)));\n\tif (it == v.end())\n\t{\n\t\tcout << \"没找到\" << endl;\n\t}\n\telse\n\t{\n\t\tcout << \"找到\" << *it << endl;\n\t}\n\n\t//排序  二元函数对象\n\tsort(v.begin(), v.end(), not2(less<int>()));\n\tfor_each(v.begin(), v.end(), [](int val){cout << val << \" \"; });\n\n}\n//not1 对一元函数对象取反\n//not2 对二元函数对象取反\n\nvoid MyPrint03(int v,int v2)\n{\n\tcout << v + v2<< \" \";\n}\n\n//3、函数指针适配器   ptr_fun\nvoid test03()\n{\n\tvector <int> v;\n\tfor (int i = 0; i < 10; i++)\n\t{\n\t\tv.push_back(i);\n\t}\n\t// ptr_fun( )把一个普通的函数指针适配成函数对象\n\tfor_each(v.begin(), v.end(), bind2nd( ptr_fun( MyPrint03 ), 100));\n}\n\n\n//4、成员函数适配器\nclass Person\n{\npublic:\n\tPerson(string name, int age)\n\t{\n\t\tm_Name = name;\n\t\tm_Age = age;\n\t}\n\n\t//打印函数\n\tvoid ShowPerson(){\n\t\tcout << \"成员函数:\" << \"Name:\" << m_Name << \" Age:\" << m_Age << endl;\n\t}\n\tvoid Plus100()\n\t{\n\t\tm_Age += 100;\n\t}\npublic:\n\tstring m_Name;\n\tint m_Age;\n};\n\nvoid MyPrint04(Person &p)\n{\n\tcout << \"姓名：\" <<  p.m_Name << \" 年龄：\" << p.m_Age << endl;\n\n};\n\nvoid test04()\n{\n\tvector <Person>v;\n\tPerson p1(\"aaa\", 10);\n\tPerson p2(\"bbb\", 20);\n\tPerson p3(\"ccc\", 30);\n\tPerson p4(\"ddd\", 40);\n\tv.push_back(p1);\n\tv.push_back(p2);\n\tv.push_back(p3);\n\tv.push_back(p4);\n\n\t//for_each(v.begin(), v.end(), MyPrint04);\n\t//利用 mem_fun_ref 将Person内部成员函数适配\n\tfor_each(v.begin(), v.end(), mem_fun_ref(&Person::ShowPerson));\n// \tfor_each(v.begin(), v.end(), mem_fun_ref(&Person::Plus100));\n// \tfor_each(v.begin(), v.end(), mem_fun_ref(&Person::ShowPerson));\n}\n\nvoid test05(){\n\n\tvector<Person*> v1;\n\t//创建数据\n\tPerson p1(\"aaa\", 10);\n\tPerson p2(\"bbb\", 20);\n\tPerson p3(\"ccc\", 30);\n\tPerson p4(\"ddd\", 40);\n\n\tv1.push_back(&p1);\n\tv1.push_back(&p2);\n\tv1.push_back(&p3);\n\tv1.push_back(&p4);\n\n\tfor_each(v1.begin(), v1.end(), mem_fun(&Person::ShowPerson));\n}\n\n//如果容器存放的是对象指针，  那么用mem_fun\n//如果容器中存放的是对象实体，那么用mem_fun_ref"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "/*\n\ntemplate<class _InIt,class _Fn1> inline\nvoid for_each(_InIt _First, _InIt _Last, _Fn1 _Func)\n{\n\tfor (; _First != _Last; ++_First)\n\t\t_Func(*_First);\n}\n\n*/\n\n//普通函数\nvoid print01(int val){\n\tcout << val << \" \";\n}\n//函数对象\nstruct print001{\n\tvoid operator()(int val){\n\t\tcout << val << \" \";\n\t}\n};\n\n//for_each算法基本用法\nvoid test01(){\n\t\n\tvector<int> v;\n\tfor (int i = 0; i < 10;i++){\n\t\tv.push_back(i);\n\t}\n\n\t//遍历算法\n\tfor_each(v.begin(), v.end(), print01);\n\tcout << endl;\n\n\tfor_each(v.begin(), v.end(), print001());\n\tcout << endl;\n\n}\n\nstruct print02{\n\tprint02(){\n\t\tmCount = 0;\n\t}\n\tvoid operator()(int val){\n\t\tcout << val << \" \";\n\t\tmCount++;\n\t}\n\tint mCount;\n};\n\n//for_each返回值\nvoid test02(){\n\n\tvector<int> v;\n\tfor (int i = 0; i < 10; i++){\n\t\tv.push_back(i);\n\t}\n\n\tprint02 p = for_each(v.begin(), v.end(), print02());\n\tcout << endl;\n\tcout << p.mCount << endl;\n}\n\nstruct print03 : public binary_function<int, int, void>{\n\tvoid operator()(int val,int bindParam) const{\n\t\tcout << val + bindParam << \" \";\n\t}\n};\n\n//for_each绑定参数输出\nvoid test03(){\n\t\n\tvector<int> v;\n\tfor (int i = 0; i < 10; i++){\n\t\tv.push_back(i);\n\t}\n\n\tfor_each(v.begin(), v.end(), bind2nd(print03(),100));\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//transform 将一个容器中的值搬运到另一个容器中\n/*\n\ttemplate<class _InIt, class _OutIt, class _Fn1> inline \n\t_OutIt _Transform(_InIt _First, _InIt _Last,_OutIt _Dest, _Fn1 _Func)\n\t{\t\n\n\t\tfor (; _First != _Last; ++_First, ++_Dest)\n\t\t\t*_Dest = _Func(*_First);\n\t\treturn (_Dest);\n\t}\n\n\ttemplate<class _InIt1,class _InIt2,class _OutIt,class _Fn2> inline\n\t_OutIt _Transform(_InIt1 _First1, _InIt1 _Last1,_InIt2 _First2, _OutIt _Dest, _Fn2 _Func)\n\t{\t\n\t\tfor (; _First1 != _Last1; ++_First1, ++_First2, ++_Dest)\n\t\t\t*_Dest = _Func(*_First1, *_First2);\n\t\treturn (_Dest);\n\t}\n*/\n\nstruct transformTest01{\n\tint operator()(int val){\n\t\treturn val + 100;\n\t}\n};\nstruct print01{\n\tvoid operator()(int val){\n\t\tcout << val << \" \";\n\t}\n};\nvoid test01(){\n\n\tvector<int> vSource;\n\tfor (int i = 0; i < 10;i ++){\n\t\tvSource.push_back(i + 1);\n\t}\n\n\t//目标容器\n\tvector<int> vTarget;\n\t//给vTarget开辟空间\n\tvTarget.resize(vSource.size());\n\t//将vSource中的元素搬运到vTarget\n\tvector<int>::iterator it = transform(vSource.begin(), vSource.end(), vTarget.begin(), transformTest01());\n\t//打印\n\tfor_each(vTarget.begin(), vTarget.end(), print01()); cout << endl;\n\t\n}\n\n//将容器1和容器2中的元素相加放入到第三个容器中\nstruct transformTest02{\n\tint operator()(int v1,int v2){\n\t\treturn v1 + v2;\n\t}\n};\nvoid test02(){\n\n\tvector<int> vSource1;\n\tvector<int> vSource2;\n\tfor (int i = 0; i < 10; i++){\n\t\tvSource1.push_back(i + 1);\t\n\t}\n\n\t//目标容器\n\tvector<int> vTarget;\n\t//给vTarget开辟空间\n\tvTarget.resize(vSource1.size());\n\ttransform(vSource1.begin(), vSource1.end(), vSource2.begin(),vTarget.begin(), transformTest02());\n\t//打印\n\tfor_each(vTarget.begin(), vTarget.end(), print01()); cout << endl;\n}"
    }
  ],
  "58954500": [],
  "58954512": [],
  "58954513": [],
  "58954515": [
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "#include \"widget.h\"\n#include <QApplication>\n\nint main(int argc, char *argv[])\n{\n    QApplication a(argc, argv);\n    Widget w;\n    w.show();\n\n    return a.exec();\n}"
    }
  ],
  "58954525": [
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "QPushButton * btn = new QPushButton; 头文件 #include <QPushButton>\n\n    //设置父亲\n    btn->setParent(this);\n    //设置文字\n    btn->setText(\"德玛西亚\");\n    //移动位置\n    btn->move(100,100);\n\n    //第二种创建\n    QPushButton * btn2 = new QPushButton(\"孙悟空\",this);\n    //重新指定窗口大小\n    this->resize(600,400);\n\n    //设置窗口标题\n    this->setWindowTitle(\"第一个项目\");\n\n    //限制窗口大小\n    this->setFixedSize(600,400);"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "{\n    QWidget window;\n    QPushButton quit(\"Quit\", &window);\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "{\n    QPushButton quit(\"Quit\");\n    QWidget window;\n    quit.setParent(&window);\n}"
    }
  ],
  "58954527": [
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "  QPushButton * quitBtn = new QPushButton(\"关闭窗口\",this);\n  connect(quitBtn,&QPushButton::clicked,this,&MyWidget::close);"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "connect(sender, signal, receiver, slot);"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "首先定义一个学生类和老师类：\n\t老师类中声明信号 饿了 hungry\nsignals:\n       void hungury();\n\t学生类中声明槽   请客 treat\n\tpublic slots:\n       void treat();\n\t在窗口中声明一个公共方法下课，这个方法的调用会触发老师饿了这个信号，而响应槽函数学生请客\n\tvoid MyWidget::ClassIsOver()\n{\n    //发送信号\n    emit teacher->hungury();\n}\n\t学生响应了槽函数，并且打印信息\n//自定义槽函数 实现\nvoid Student::eat()\n{\n       qDebug() << \"该吃饭了！\";\n}\n在窗口中连接信号槽\n    teacher = new Teacher(this);\n    student = new Student(this);\n\n    connect(teacher,&Teacher::hungury,student,&Student::treat);\n并且调用下课函数，测试打印出 “该吃饭了”"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "自定义的信号 hungry带参数，需要提供重载的自定义信号和 自定义槽\nvoid hungury(QString name); 自定义信号\nvoid treat(QString name ); 自定义槽\n但是由于有两个重名的自定义信号和自定义的槽，直接连接会报错，所以需要利用函数指针来指向函数地址， 然后在做连接\nvoid (Teacher:: * teacherSingal)(QString) = &Teacher::hungury;\nvoid (Student:: * studentSlot)(QString) = &Student::treat;\nconnect(teacher,teacherSingal,student,studentSlot);"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "connect(zt,SIGNAL(hungry(QString)),st,SLOT(treat(QString)));"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "[capture](parameters) mutable ->return-type\n{\nstatement\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "    QPushButton * myBtn = new QPushButton (this);\n    QPushButton * myBtn2 = new QPushButton (this);\n    myBtn2->move(100,100);\n    int m = 10;\n\n    connect(myBtn,&QPushButton::clicked,this,[m] ()mutable { m = 20; qDebug() << m; });\n\n    connect(myBtn2,&QPushButton::clicked,this,[=] ()  { qDebug() << m; });\n\n    qDebug() << m;"
    }
  ],
  "58954529": [
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "QMenuBar *menuBar() const"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "QAction* addMenu(QMenu * menu)\nQMenu* addMenu(const QString & title)\nQMenu* addMenu(const QIcon & icon, const QString & title)"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "QAction* activeAction() const\nQAction* addAction(const QString & text)\nQAction* addAction(const QIcon & icon, const QString & text)\nQAction* addAction(const QString & text, const QObject * receiver,\nconst char * member, const QKeySequence & shortcut = 0)\nQAction* addAction(const QIcon & icon, const QString & text,\nconst QObject * receiver, const char * member,\nconst QKeySequence & shortcut = 0)"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//添加小部件\nvoid addWidget(QWidget * widget, int stretch = 0)\n//插入小部件\nintinsertWidget(int index, QWidget * widget, int stretch = 0)\n//删除小部件\nvoid removeWidget(QWidget * widget)"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "QDockWidget * dock = new QDockWidget(\"标题\",this);\n    addDockWidget(Qt::LeftDockWidgetArea,dock);\ndock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::TopDockWidgetArea);  设置区域范围"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "QTextEdit * edit = new QTextEdit(this);\nsetCentralWidget(edit);"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "<RCC>\n<qresource prefix=\"/images\">\n<file alias=\"doc-open\">document-open.png</file>\n</qresource>\n<qresource prefix=\"/images/fr\" lang=\"fr\">\n<file alias=\"doc-open\">document-open-fr.png</file>\n</qresource>\n</RCC>"
    }
  ],
  "58954535": [
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "QDialog dialog;\ndialog.setWindowTitle(tr(\"Hello, dialog!\"));\ndialog.exec();"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "QDialog dialog(this);\ndialog.setWindowTitle(tr(\"Hello, dialog!\"));\ndialog.show();"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "QDialog *dialog = new QDialog;\ndialog->setWindowTitle(tr(\"Hello, dialog!\"));\ndialog->show();"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "QDialog *dialog = new QDialog;\ndialog->setAttribute(Qt::WA_DeleteOnClose);\ndialog->setWindowTitle(tr(\"Hello, dialog!\"));\ndialog->show();"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "void about(QWidget * parent, const QString & title, const QString & text)"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "void aboutQt(QWidget * parent, const QString & title = QString())："
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "StandardButton critical(QWidget * parent,\nconst QString & title,\nconst QString & text,\nStandardButtons buttons = Ok,\nStandardButton defaultButton = NoButton)："
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "StandardButton information(QWidget * parent,\nconst QString & title,\nconst QString & text,\nStandardButtons buttons = Ok,\nStandardButton defaultButton = NoButton)"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "StandardButton question(QWidget * parent,\nconst QString & title,\nconst QString & text,\nStandardButtons buttons = StandardButtons( Yes | No ),\nStandardButton defaultButton = NoButton)"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "StandardButton warning(QWidget * parent,\nconst QString & title,\nconst QString & text,\nStandardButtons buttons = Ok,\nStandardButton defaultButton = NoButton)"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "if (QMessageBox::Yes == QMessageBox::question(this,\ntr(\"Question\"), tr(\"Are you OK?\"),\nQMessageBox::Yes | QMessageBox::No,\nQMessageBox::Yes))\n{\nQMessageBox::information(this, tr(\"Hmmm...\"),\ntr(\"I'm glad to hear that!\"));\n}\nelse\n{\nQMessageBox::information(this, tr(\"Hmmm...\"),\ntr(\"I'm sorry!\"));\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "QMessageBox msgBox;\nmsgBox.setText(tr(\"The document has been modified.\"));\nmsgBox.setInformativeText(tr(\"Do you want to save your changes?\"));\nmsgBox.setDetailedText(tr(\"Differences here...\"));\nmsgBox.setStandardButtons(QMessageBox::Save\n                          | QMessageBox::Discard\n                          | QMessageBox::Cancel);\nmsgBox.setDefaultButton(QMessageBox::Save);\nint ret = msgBox.exec();\nswitch (ret) \n{\ncase QMessageBox::Save:\n    qDebug() << \"Save document!\";\n    break;\ncase QMessageBox::Discard:\n    qDebug() << \"Discard changes!\";\n    break;\ncase QMessageBox::Cancel:\n    qDebug() << \"Close document!\";\n    break;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "openAction = new QAction(QIcon(\":/images/file-open\"),tr(\"&Open...\"), this);\nopenAction->setStatusTip(tr(\"Open an existing file\"));\n\nsaveAction = new QAction(QIcon(\":/images/file-save\"), tr(\"&Save...\"), this);\nsaveAction->setStatusTip(tr(\"Save a new file\"));\n\nQMenu *file = menuBar()->addMenu(tr(\"&File\"));\nfile->addAction(openAction);\nfile->addAction(saveAction);\n\nQToolBar *toolBar = addToolBar(tr(\"&File\"));\ntoolBar->addAction(openAction);\ntoolBar->addAction(saveAction);\n\ntextEdit = new QTextEdit(this);\nsetCentralWidget(textEdit);"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "connect(openAction, &QAction::triggered, \nthis, &MainWindow::openFile);\nconnect(saveAction, &QAction::triggered, \nthis, &MainWindow::saveFile);"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//打开文件\nvoid MainWindow::openFile()\n{\n    QString path = QFileDialog::getOpenFileName(this,\n               tr(\"Open File\"), \".\", tr(\"Text Files(*.txt)\"));\n    if(!path.isEmpty()) \n{\n        QFile file(path);\n        if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) \n{\n            QMessageBox::warning(this, tr(\"Read File\"),\n                         tr(\"Cannot open file:\\n%1\").arg(path));\n            return;\n        }\n        QTextStream in(&file);\n        textEdit->setText(in.readAll());\n        file.close();\n    } \nelse \n{\n        QMessageBox::warning(this, tr(\"Path\"),\n                             tr(\"You did not select any file.\"));\n     }\n}\n\n//保存文件\nvoid MainWindow::saveFile()\n{\n    QString path = QFileDialog::getSaveFileName(this,\n               tr(\"Open File\"), \".\", tr(\"Text Files(*.txt)\"));\n    if(!path.isEmpty()) \n{\n        QFile file(path);\n        if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) \n{\n            QMessageBox::warning(this, tr(\"Write File\"),\n                         tr(\"Cannot open file:\\n%1\").arg(path));\n            return;\n        }\n        QTextStream out(&file);\n        out << textEdit->toPlainText();\n        file.close();\n    } \nelse \n{\n        QMessageBox::warning(this, tr(\"Path\"),\n                             tr(\"You did not select any file.\"));\n    }\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "QString getOpenFileName(QWidget * parent = 0,\n                        const QString & caption = QString(),\n                        const QString & dir = QString(),\n                        const QString & filter = QString(),\n                        QString * selectedFilter = 0,\n                        Options options = 0)"
    }
  ],
  "58954536": [],
  "58954540": [
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "voidsetText(const QString &)"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "QLable *label = new QLable;\nlabel->setText(\"Hello, World!\");"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "QLabel * label = new QLabel(this);\nlabel ->setText(\"Hello, World\");\nlabel ->setText(\"<h1><a href=\\\"https://www.baidu.com\\\">百度一下</a></h1>\");\nlabel ->setOpenExternalLinks(true);"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "voidsetPixmap(const QPixmap &)"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "QPixmap pixmap;"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "pixmap.load(\":/Image/boat.jpg\");"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "QLabel *label = new QLabel;\nlabel.setPixmap(pixmap);"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "voidsetMovie(QMovie * movie)"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "QMovie *movie = new QMovie(\":/Mario.gif\");"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "movie->start();"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "QLabel *label = new QLabel；\nlabel->setMovie(movie);"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "QStringtext() const"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "voidsetText(const QString &)"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "voidsetEchoMode(EchoMode mode)"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "void setTextMargins(int left, int top, int right, int bottom)"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "// smallwidget.h\nclass SmallWidget : public QWidget\n{\nQ_OBJECT\npublic:\nexplicit SmallWidget(QWidget *parent = 0);\nsignals:\npublic slots:\nprivate:\nQSpinBox* spin;\nQSlider* slider;\n};\n// smallwidget.cpp\nSmallWidget::SmallWidget(QWidget *parent) : QWidget(parent)\n{\nspin = new QSpinBox(this);\nslider = new QSlider(Qt::Horizontal, this);\n// 创建布局对象\nQHBoxLayout* layout = new QHBoxLayout;\n// 将控件添加到布局中\nlayout->addWidget(spin);\nlayout->addWidget(slider);\n// 将布局设置到窗口中\nsetLayout(layout);\n// 添加消息响应\nconnect(spin,\nstatic_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),\nslider, &QSlider::setValue);\nconnect(slider, &QSlider::valueChanged,\nspin, &QSpinBox::setValue);\n}"
    }
  ],
  "58954546": [
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class EventLabel : public QLabel\n{\nprotected:\n    void mouseMoveEvent(QMouseEvent *event);\n    void mousePressEvent(QMouseEvent *event);\n    void mouseReleaseEvent(QMouseEvent *event);\n};\n \nvoid EventLabel::mouseMoveEvent(QMouseEvent *event)\n{\nthis->setText(QString(\"<center><h1>Move: (%1, %2)\n</h1></center>\").arg(QString::number(event->x()),\n            QString::number(event->y())));\n}\n \nvoid EventLabel::mousePressEvent(QMouseEvent *event)\n{\n    this->setText(QString(\"<center><h1>Press:(%1, %2)\n</h1></center>\").arg(QString::number(event->x()),\n                QString::number(event->y())));\n}\n \nvoid EventLabel::mouseReleaseEvent(QMouseEvent *event)\n{\n    QString msg;\n    msg.sprintf(\"<center><h1>Release: (%d, %d)</h1></center>\",\n                event->x(), event->y());\n    this->setText(msg);\n}\n \nint main(int argc, char *argv[])\n{\n    QApplication a(argc, argv);\n \n    EventLabel *label = new EventLabel;\n    label->setWindowTitle(\"MouseEvent Demo\");\n    label->resize(300, 200);\n    label->show();\n \n    return a.exec();\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "label->setMouseTracking(true);"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "bool CustomWidget::event(QEvent *e)\n{\nif (e->type() == QEvent::KeyPress) {\nQKeyEvent *keyEvent = static_cast<QKeyEvent *>(e);\nif (keyEvent->key() == Qt::Key_Tab) {\nqDebug() << \"You press tab.\";\nreturn true;\n}\n}\nreturn QWidget::event(e);\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "bool CustomTextEdit::event(QEvent *e)\n{\nif (e->type() == QEvent::KeyPress)\n{\nQKeyEvent *keyEvent = static_cast<QKeyEvent *>(e);\nif (keyEvent->key() == Qt::Key_Tab)\n{\nqDebug() << \"You press tab.\";\nreturn true;\n}\n}\nreturn false;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "switch (event->type()) {\ncase QEvent::MouseMove:\nmouseMoveEvent((QMouseEvent*)event);\nbreak;\n// ...\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "//!!! Qt5\nbool QObject::event(QEvent *e)\n{\nswitch (e->type()) {\ncase QEvent::Timer:\ntimerEvent((QTimerEvent*)e);\nbreak;\ncase QEvent::ChildAdded:\ncase QEvent::ChildPolished:\ncase QEvent::ChildRemoved:\nchildEvent((QChildEvent*)e);\nbreak;\n// ...\ndefault:\nif (e->type() >= QEvent::User) {\ncustomEvent(e);\nbreak;\n}\nreturn false;\n}\nreturn true;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class MainWindow : public QMainWindow\n{\npublic:\nMainWindow();\nprotected:\nbool eventFilter(QObject *obj, QEvent *event);\nprivate:\nQTextEdit *textEdit;\n};\nMainWindow::MainWindow()\n{\ntextEdit = new QTextEdit;\nsetCentralWidget(textEdit);\ntextEdit->installEventFilter(this);\n}\nbool MainWindow::eventFilter(QObject *obj, QEvent *event)\n{\nif (obj == textEdit) {\nif (event->type() == QEvent::KeyPress) {\nQKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);\nqDebug() << \"Ate key press\" << keyEvent->key();\nreturn true;\n} else {\nreturn false;\n}\n} else {\n// pass the event on to the parent class\nreturn QMainWindow::eventFilter(obj, event);\n}\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "bool CustomWidget::event(QEvent *e)\n{\nif (e->type() == QEvent::KeyPress) {\nQKeyEvent *keyEvent = static_cast<QKeyEvent *>(e);\nif (keyEvent->key() == Qt::Key_Tab) {\nqDebug() << \"You press tab.\";\nreturn true;\n}\n}\nreturn QWidget::event(e);\n}\n现在，我们可以给出一个使用事件过滤器的版本：\nbool FilterObject::eventFilter(QObject *object, QEvent *event)\n{\nif (object == target && event->type() == QEvent::KeyPress)\n{\nQKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);\nif (keyEvent->key() == Qt::Key_Tab) {\nqDebug() << \"You press tab.\";\nreturn true;\n} else {\nreturn false;\n}\n}\nreturn false;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "LRESULT CALLBACK WndProc(HWND hWnd,\nUINT message,\nWPARAM wParam,\nLPARAM lParam)"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "switch(message)\n{\ncase WM_PAINT:\n// ...\nbreak;\ncase WM_DESTROY:\n// ...\nbreak;\n...\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "virtual bool QCoreApplication::notify ( QObject * receiver,\nQEvent * event );"
    }
  ],
  "58954548": [
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "class PaintedWidget : public QWidget\n{\nQ_OBJECT\npublic:\nPaintedWidget(QWidget *parent = 0);\nprotected:\nvoid paintEvent(QPaintEvent *);\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "PaintedWidget::PaintedWidget(QWidget *parent) :\nQWidget(parent)\n{\nresize(800, 600);\nsetWindowTitle(tr(\"Paint Demo\"));\n}\nvoid PaintedWidget::paintEvent(QPaintEvent *)\n{\nQPainter painter(this);\npainter.drawLine(80, 100, 650, 500);\npainter.setPen(Qt::red);\npainter.drawRect(10, 10, 100, 400);\npainter.setPen(QPen(Qt::green, 5));\npainter.setBrush(Qt::blue);\npainter.drawEllipse(50, 150, 400, 200);\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "void PaintWidget::paintEvent(QPaintEvent *)\n{\nQPixmap pixmap(\":/Image/butterfly.png\");\nQPixmap pixmap1(\":/Image/butterfly1.png\");\nQBitmap bitmap(\":/Image/butterfly.png\");\nQBitmap bitmap1(\":/Image/butterfly1.png\");\nQPainter painter(this);\npainter.drawPixmap(0, 0, pixmap);\npainter.drawPixmap(200, 0, pixmap1);\npainter.drawPixmap(0, 130, bitmap);\npainter.drawPixmap(200, 130, bitmap1);\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "void PaintWidget::paintEvent(QPaintEvent *)\n{\nQPainter painter(this);\nQImage image(300, 300, QImage::Format_RGB32);\nQRgb value;\n//将图片背景填充为白色\nimage.fill(Qt::white);\n//改变指定区域的像素点的值\nfor(int i=50; i<100; ++i)\n{\nfor(int j=50; j<100; ++j)\n{\nvalue = qRgb(255, 0, 0); // 红色\nimage.setPixel(i, j, value);\n}\n}\n//将图片绘制到窗口中\npainter.drawImage(QPoint(0, 0), image);\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "void PaintWidget::paintEvent(QPaintEvent *)\n{\nQPicture pic;\nQPainter painter;\n//将图像绘制到QPicture中,并保存到文件\npainter.begin(&pic);\npainter.drawEllipse(20, 20, 100, 50);\npainter.fillRect(20, 100, 100, 100, Qt::red);\npainter.end();\npic.save(\"D:\ndrawing.pic\");\n//将保存的绘图动作重新绘制到设备上\npic.load(\"D:\ndrawing.pic\");\npainter.begin(this);\npainter.drawPicture(200, 200, pic);\npainter.end();\n}"
    }
  ],
  "58954552": [
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "int main(int argc, char *argv[])\n{\n    QApplication app(argc, argv);\n \n    QFile file(\"in.txt\");\n    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {\n        qDebug() << \"Open file failed.\";\n        return -1;\n    } else {\n        while (!file.atEnd()) {\n            qDebug() << file.readLine();\n        }\n    }\n \n    QFileInfo info(file);\n    qDebug() << info.isDir();\n    qDebug() << info.isExecutable();\n    qDebug() << info.baseName();\n    qDebug() << info.completeBaseName();\n    qDebug() << info.suffix();\n    qDebug() << info.completeSuffix();\n \n    return app.exec();\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "QFileInfo fi(\"/tmp/archive.tar.gz\");\nQString base = fi.baseName(); // base = \"archive\"\nQString base = fi.completeBaseName(); // base = \"archive.tar\"\nQString ext = fi.suffix(); // ext = \"gz\"\nQString ext = fi.completeSuffix(); // ext = \"tar.gz\""
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "QFile file(\"file.dat\");\nfile.open(QIODevice::WriteOnly);\nQDataStream out(&file);\nout << QString(\"the answer is\");\nout << (qint32)42;"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "QFile file(\"file.dat\");\nfile.open(QIODevice::ReadOnly);\nQDataStream in(&file);\nQString str;\nqint32 a;\nin >> str >> a;"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "QFile file(\"file.dat\");\nfile.open(QIODevice::ReadWrite);\nQDataStream stream(&file);\nQString str = \"the answer is 42\";\nstream << str;"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "QFile data(\"file.txt\");\nif (data.open(QFile::WriteOnly | QIODevice::Truncate))\n{\nQTextStream out(&data);\nout << \"The answer is \" << 42;\n}"
    },
    {
      "lang": "cpp",
      "params": {
        "language": "cpp"
      },
      "code": "QFile data(\"file.txt\");\nif (data.open(QFile::ReadOnly))\n{\nQTextStream in(&data);\nQString str;\nint ans = 0;\nin >> str >> ans;\n}"
    }
  ]
}