- 博客(57)
- 收藏
- 关注
原创 C++中的Array Decay(数组退化)
文章目录一、问题描述二、解决方法一、问题描述将数组传递给函数的时候,数组会退化成指针。 二、解决方法#include "iostream"#include "string"#include "vector"using namespace std;//以指针接受数组时产生Array Decayvoid test01(int *p) { cout << sizeof(p) << endl;}//此种形式依旧不能解决数组退化void te
2022-05-23 21:50:46
535
原创 C++容器空间配置器allocator
文章目录一、自己根据逻辑实现的容器二、存在的问题三、解决办法四、空间配置器的实现一、自己根据逻辑实现的容器template<typename T>class SeqStack {public: SeqStack(int size = 10) : _size(size), _top(-1) { _pstack = new T[size]; } SeqStack(const SeqStack<
2022-05-07 19:00:16
675
原创 C++模板
文章目录一、函数模板二、类模板一、函数模板template<typename T> //模板的参数列表bool compare(T a, T b) { //函数的模板 cout << "compare template" << endl; return a > b;} 模板实例化//函数调用点compare<int>(10, 11) //在函数调用点,编译器使用用户指定的类型,从原模板实例化一
2022-05-07 18:29:56
336
原创 C++语言级别的类型转换
文章目录一、const_cast二、static_cast三、reinterpret_cast四、dynamic_cast一、const_cast把常量属性去掉的类型转换const_cast只能去除const限制,其他的类型不能转换,const_cast只能用于指针或引用 二、static_cast提供编译器认为安全的类型转换(没有任何关联的类型之间不允许转换),编译时期的类型转换。 三、reinterpret_cast类似于C风格的强制类型转换(不一定安全)&nb
2022-05-06 19:24:23
471
原创 C++中两个头文件相互包含
文章目录一、问题描述二、解决方法一、问题描述 A.h#ifndef A_H#define A_H#include "B.h"class A{ typedef vector<string>::sizetype size_type; B b;}#endifB.h#ifndef B_H#define B_H#include "A.h"class B{ A::size_type num;}#endifA.h和B.h相互包含会编译错误
2022-05-04 17:04:18
1622
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人