![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C/C++
yj_coder
这个作者很懒,什么都没留下…
展开
-
C++中引用的用法和实验代码
主要有以下两点: 1.当函数返回值为引用类型时,没有复制return的对象,而返回的是return的对象本身。 2.返回引用时,要求在函数的参数中,包含有以引用方式或指针方式存在的,需要被返回的参数。 实验代码如下: #include <iostream> using namespace std; int a = 5; int c = 2; int &b = c; i...原创 2018-11-09 21:06:13 · 154 阅读 · 0 评论 -
成员变量的继承
1. 输出是4 #include <stdio.h> #include <iostream> using namespace std; class Parent { public: Parent(){ a = 2; } void print() { cout << a << endl; } protected: int a...原创 2019-07-02 10:23:36 · 617 阅读 · 0 评论 -
回调函数
原创 2019-06-26 14:05:27 · 98 阅读 · 0 评论 -
深拷贝和浅拷贝
原创 2019-06-26 11:02:47 · 126 阅读 · 0 评论 -
函数式宏定义
原创 2019-06-26 10:44:38 · 536 阅读 · 0 评论 -
定义数组指针
原创 2019-06-26 10:40:26 · 996 阅读 · 0 评论 -
typedef的使用
例1: 例2: 例3:原创 2019-06-25 16:16:23 · 105 阅读 · 0 评论 -
位运算移位时注意的问题
在做leetcode 50题时,第一次提交发生了错误,原因是我把“/2”写成了“>>1”。然后我查资料发现,只有是正数时,右移一位和对2求模的结果是相同的,如果是负数,那么就只能用对2求模,右移得到的结果是错误的。以前不知道这个事,以后得注意。。 ...原创 2019-04-02 20:16:53 · 352 阅读 · 0 评论 -
记录与string.size()有关的一个问题
在做leetcode 30题时,开始提交有一个测试用例过不去: 输入:s = "mississippi", words = ["mississippis"]. 提示我执行出错,一开始百思不得其解,后来我发现是下面的问题,贴在这里的最后一行出现的问题。 //int slen = s.size(); for(int i = 0; i < len; i++){ ...原创 2019-04-02 19:39:15 · 503 阅读 · 2 评论 -
“+=” string时遇到的问题
这是我在做leetcode 38题时遇到的坑,调试了好久才发现这个问题,如下。 #include <iostream> #include <string> using namespace std; int main(){ string ans = "23"; string temp; //(right) //temp = temp + to_string(...原创 2019-03-30 14:07:48 · 231 阅读 · 0 评论 -
实现智能指针shared_ptr
#include <memory> #include <iostream> using namespace std; template<class T> class SmartPtr { private: T* _ptr; int* use_count; public: //构造函数 SmartPtr(T* ptr = nullptr) :_pt...原创 2019-07-13 16:41:43 · 202 阅读 · 0 评论