2 weixin_41157881

尚未进行身份认证

暂无相关简介

等级
TA的排名 4w+

memset和sprintf小记

#include#include#includeusing namespace std;struct Test{string a;string b;};int main(){Test ta{“123”,“abc”};cout << ta.a << " " << ta.b << endl;memset(&ta, 0, ...

2019-12-30 22:23:46

类的继承的实例

#include#include#include#include #include #includeusing namespace std;class Base{public:virtual void display() = 0;};class A :public Base{public:void display(){cout << “A class”...

2019-12-30 22:21:28

N个括号有多少种合法的组合

两种算法,思想都是左括号始终大于等于右括号,当左括号等于右括号的时候且等于N的时候。记录为1#include#include#include#include #include #include#includeusing namespace std;void display(int x, int y){cout << x << " " << ...

2019-12-12 22:13:10

C++11的一种多线程安全的单例模式

#include #include using namespace std;class Test{public:Test(){cout << “create Test class” << endl;num++;cout << “create Test class finish” << endl;}void ttt(){st...

2019-12-11 23:20:36

C++访问控制

#includeusing namespace std;class base{public:int a = 555;private:int b = 666;protected:int c = 777;};class publicTest :public base{public:void fun(){cout << "publicTest: ";cout...

2019-12-09 22:42:03

类中的枚举变量

#includeusing namespace std;class A{public:enum Test{ONE,TWO,THREE};};int main(){cout << sizeof(A) << endl;//枚举变量不占用类的空间A::Test b = A::TWO;cout << int(b) << end...

2019-11-27 20:55:03

c++14 lambdas新特性

#include #include using namespace std;int main(){std::unique_ptr<int> p(new int);int x = 5;*p = 11;auto y = [p = std::move(p)]() { std::cout << "inside: " << *p << "\n"...

2019-11-26 23:18:23

智能指针的使用

#include#include#include#includeusing namespace std;class SreBob{public:SreBob();SreBob(initializer_list il);//大括号初始化的调用的函数int size()const { return data->size(); }bool empty()const { ret...

2019-11-25 21:28:00

C++重载

#includeusing namespace std;int maxt(int a, int b){if (a > b){return a;}return b;}int maxt(int a, int b,int c){if (a > b && a > c){return a;}else if (b > a &&am...

2019-11-24 21:34:45

智能指针实现单链表

#include#include#include#includeusing namespace std;struct LinkNode;using sharedPtr = std::shared_ptr;struct LinkNode{int val;sharedPtr next;};class LinkList{private:int length;sharedP...

2019-11-23 22:29:16

定时器的实现

#include#include#include#includeusing namespace std;#define MSOFDAY (246060*1000UL)void func(char str[100]){cout << sizeof(str) << endl;}class Timer{public:void fun(int num, s...

2019-11-19 23:39:31

C++模板编程新的小特点

#includeusing namespace std;template<int *p>struct wrapper{int get() { return *p; }void set(int v) { *p = v; }};template<int &p>struct wrapper1{int get() { return p; }void ...

2019-11-16 22:45:39

一系列测试题目

#includeusing namespace std;void Foo(char str1[100]){cout << "sizeof(str) = " << sizeof(str1) << endl;}void GetM1(char *p){p = (char *)malloc(100);}void test1(void){char ...

2019-11-13 22:27:01

一系列小的题目

#include#includeusing namespace std;class A{public:virtual void f() = 0;};class B :virtual public A{public:void f(){cout << “B” << endl;}};class C :virtual public A{publi...

2019-11-11 21:50:56

一系列小的题目

#include#include#include#include #include #include#include#includeusing namespace std;class A{public:A() :c(3), b©, a(b) {}public:int a;int b;int c;};class MyString{public:explici...

2019-11-09 23:24:05

const_cast、static_cast、dynamic_cast总结实例

#include#include#include#include #include using namespace std;struct SA{int i;};enum enumtest{A=1,B};class Base{public:int m;virtual void fun(){}};class Dclass :public Base{pub...

2019-11-06 22:04:15

一系列自测题目

#include#include#include#includeusing namespace std;class A{private:A(){cout << “create A” << endl;}int a1 = 100;static A a;static std::mutex mtx;public:static A getA(){i...

2019-11-05 23:02:17

一系列题目自检

#include#include#include#include#includeusing namespace std;struct LinkNode{int val;LinkNode *next;LinkNode(int val, LinkNode *next = nullptr){this->val = val;this->next = next;}}...

2019-11-04 23:24:18

信号量的实现和使用

#include#include#include<condition_variable>#include#includeusing namespace std;class Semaphore{public:explicit Semaphore(unsigned int count);~Semaphore();public:void wait();void si...

2019-09-29 00:30:47

[LeetCode] 905. Sort Array By Parity 按奇偶排序数组

前后指针操作即可。#include#includeusing namespace std;void SortArrayByParity(vector &vec){int left = 0;int right = vec.size() - 1;while (left < right){while (left < right && vec[lef...

2019-09-27 00:01:10

查看更多

勋章 我的勋章
  • 持之以恒
    持之以恒
    授予每个自然月内发布4篇或4篇以上原创或翻译IT博文的用户。不积跬步无以至千里,不积小流无以成江海,程序人生的精彩需要坚持不懈地积累!
  • 勤写标兵Lv2
    勤写标兵Lv2
    授予每个自然周发布4篇到6篇原创IT博文的用户。本勋章将于次周周三上午根据用户上周的博文发布情况由系统自动颁发。