拷贝构造函数与赋值
拷贝构造函数String(const String& other) =delete; 赋值void operator=(const String& )=delete; 只要产生新对象其实就是调用了拷贝构造函数 class String { private: char *m_Buffer; unsigned int m_Size; public: String(const char *string) { ...
2024.08.11
从0开始的Leetcode 做题记录
丑陋的代码 第一天两数之和class Solution { public: vector<int> twoSum(vector<int>& nums, int target) { int i = 0; int j = 0; while (1) { int sum; if (i==j) ...
2024.08.01
一些C++的代码实例
C++单例设计实现class S { public: static S &getInstance() { static S instance; return instance; } private: S() {} public: S(S const &) = delete; void operator=(S const &) = delete; }; ...
2024.07.30
一些不常用的C++的关键字的记录
mutable 关键字允许有const的函数中修改值 class Entiy{ public: mutable int var; int val; void GetVal () const { var = 3; //Allow,because var is mutable val=6; //Not Allow } }; ...
2024.07.30
快速区分常量指针和指针常量的一种歪门邪道
int* const a = new int; //指针常量 const int* b = new int; //常量指针 先删除类型成为 * const a = new int; const *b = new int; 然后从=右侧向左侧看,其中*b可以看作先解引用,在被const修饰,所以把*b当作一个值,const valve 即可以看作为值不可变,也就是说第二句中指针指向的值不可变而* const a 中a 没有被解引用,所以看作它是内存地址,又 ...
2024.07.30
Hello World
你好,世界这是第一篇文章I Love You ...
2024.07.30